joomlajoomla3.0

Joomla 3.0: pass parameter to edit form


This is my problem: I need to pass a parameter to edit form of joomla, so link will be like this: https://mydomain.com/administrator/index.php?option=com_mycom&task=mycom.edit&type=country&id=233. The param "type" must be send to my edit form. But i cannot get it by this way in my "view.html.php" file

$input = JFactory::getApplication()->input 
$type = $input->getVar("type");

Cause the link always remove the "type" param


Solution

  • Link you mentioned link executes controller method edit in com_mycom/controllers/mycom.php that extends JControllerForm where things happens like item check-in, ACL checks, etc. and user might be redirected to the edit form (see JControllerForm::edit).

    Anything but table key (usually item id) is stripped out from the query.

    Copy over default edit method to your subcontroller and modify to read things you want

    public function edit($key = null, $urlVar = null)
    {
        $app   = JFactory::getApplication();
        $type  = $app->input->get->('type', null');
    
        //...
    

    Later on in redirect for new and existing items append '&type=' . $type to url query

    $this->setRedirect(
        JRoute::_(
            'index.php?option=' . $this->option . '&view=' . $this->view_list . '&type=' . $type