5

Hi I have a question about Joomla forms. I want to understand how Joomla works internally, especially I'm interested in com_installer component to know how it's working. And I found a form in default.php file in com_installer/views/install/tmpl folder.

In this file there are custom buttons for submitting a form. And I'm interested in how the buttons are actually trigger the installation of components, modules or other things itself. In the form body I see some hidden values like

<input type="hidden" name="task" value="install.install" />

So this hidden value probably trigger a installation by calling a install controller and install method of that controller.

But the question is how Joomla does this? Where is the code redirecting the url from view=install to task=install.install? In other words how Joomla knows that the value form the hidden input should go to the url?

migrated from stackoverflow.com May 9 '14 at 15:02

This question came from our site for professional and enthusiast programmers.

  • You have to look at the mvc classes to really understand the how part, but also in your case you should look at JToolbar which is in the includes folder of the administrator. – Elin May 8 '14 at 23:07
3

@RiccardoZorn is correct at the base level. There are two hidden form fields that are commonly set: option and task.

Option: The component name such as com_example directs the page to load that component.

Task: A controller function or a controller and a function to call. If it has a '.' in it then the part before that specifies a controller to load and then call the function with the name of the part after the period. If there is no period, then it will just run the function in the default controller (usually controller.php in the base folder of the component.


You also specifically ask about the toolbar buttons. This involves a little bit of javascript that automatically is loaded by Joomla to power the buttons.

When the button is clicked, it should trigger Joomla.submitbutton(). This function takes a value that is the task to set based on the button clicked. So if you click the save button, this will commonly set the task to import.save. (I don't think that button actually exists in this component, but many others will have that.)

The submitbutton function by default just pushes that to another function submitform. This function will then shift that task into the appropriate hidden field. Finally this submits the form.

So even though those toolbar buttons are not submit buttons (or even in the form tag usually) they will still update the hidden value of task and submit the form using javascript.

You can find the core javascript functions here: media/system/js/core-uncompressed.js

  • Hi David. Thank you for your very interesting answer. I can learn form it much although it dont answer my question but I know now the answer. I was having a problem of understanding how the Install & Upload button of com_install is trigering a install() function of install controller because I assume that Joomla can only figure out what to display based on the url. And I thought that when in the form is a hidden task value, this value somehow need to be put back into the url so Joomla can interpret this. – Bogdan May 9 '14 at 18:47
  • But actually now I know that Joomla is figuring out the task and other variables directly from $_REQUEST[] array that contains not only $_GET variables from url but also $_POST variables from hidden form fields. So case is solved. I appreciate all the answers. They were really informative especially David's answer. – Bogdan May 9 '14 at 18:48
2

The task is either a method in the controller.php in the main component folder (if it's a single word), or the name of the controller and its method separated by a dot, i.e. install.install will be parsed by the method install() in controllers/install.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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