5

I do display and save forms in Joomla MVC components using jmodeladmin classes.

But how can I do same thing from a module? As modules don't do things in the MVC way that automatically can find the corresponding view, model and controller.

So I guess I would display a form giving following what is mentioned in this post How to get the form of component from module? but when form's submit button is clicked in the concerned module, how can I catch the submission & save using jmodeladmin classes??

2 Answers 2

4

I would think you need to catch the output from your module using a component. You can use JForm to output the form in your module, and then have hidden inputs like

<form action="index.php" method="POST" name="yourform">
<input type="hidden" value="com_yourcomponent" name="option"/>
<input type="hidden" value="yourview" name="view"/>
<input type="hidden" value="savesomething" name="task"/>
<!-- ...and other input-fields with your actual form input -->
</form>

then you can use all the usual methods to handle the form input...

2
  • It's bit messier to use another component, isn't it?. So for my purpose, I think it could be easier if i create a new model instance and overwriting it's getForm() method by specifying a form located right in the module folder and display it and when form submission occur i call model's save() method to save in my custom module table.how can i do that start to last without using any component's model and form.I guess it sounds ok in terms of implementing independent module?
    – dev-m
    May 13, 2014 at 20:57
  • I agree it looks messier with a component, but in my experience you always get into trouble trying to handle forms entirely with modules, as, as you say, they dont really support the whole mvc-thingy. But check @ChadWindnagle 's answer, it looks promising :)
    – jonasfh
    May 14, 2014 at 7:20
3

You're right the submit with a module is a bit more difficult because form submits have to go to a URL. It is messier to have to write a component just to accept the input from the module too.

Because of this issue, in Joomla 3 is Matt Thomas wrote a component called com_ajax. Com_Ajax is a component that is designed to assist modules with doing things with modules when there wasn't a specific URL to work with like you have in a component.

Your case to me is exactly what com_ajax was designed to help deal with. Here's some documentation on using it:

http://docs.joomla.org/Using_Joomla_Ajax_Interface

What you're going to end up doing with your module is writing a which will get executed via the submit URL. I think you'll want to use some javascript to assist with the form submit there but I'm not sure if it's completely necessary (but it is sexier).

Then in your helper you'll set up the class for the module:

https://github.com/Joomla-Ajax-Interface/Ajax-Session-Module/blob/master/helper.php#L12

You will set up with getAjax() method: https://github.com/Joomla-Ajax-Interface/Ajax-Session-Module/blob/master/helper.php#L12

To handle pulling in the form submit data via JFactory::getApplication()->input()

You will then return some sort of response, probably something like a JSON string which is a success or error message.

Hopefully this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.