0

After submitting a form, the page refresh with a thank you message. So how can I redirect that page to a different url after successfully submitting the form.

Current Form codes are as following:

<form id="contactCompanyFrm" name="contactCompanyFrm" action="<?php echo JRoute::_('index.php?option=com_jbusinessdirectory') ?>" method="post">
## form fields
<?php echo JHTML::_( 'form.token' ); ?>
<input type='hidden' name='task' id="task" value='companies.contactCompany'/>
<input type="hidden" name="companyId" id="companyId" value="" />
</form>

Controller page:

class JBusinessDirectoryControllerCompanies extends JControllerLegacy
{
function contactCompany(){
    $appSettings = JBusinessUtil::getInstance()->getApplicationSettings();
    $model = $this->getModel('companies');

    $data = JRequest::get( 'post' );
    $companyId = JRequest::getVar('companyId');
    $contactId = JRequest::getVar('contactId');
    $company = $model->getPlainCompany($companyId);

    $data['contact_id'] = $contactId;

    $result = $model->contactCompany($data);

    if($result){
        $this->setMessage(JText::_('ABC Good'));
    }else{
        $this->setMessage(JText::_('XYZ Bad'));
    }

    $model->saveCompanyMessages();
    $this->setRedirect(JBusinessUtil::getCompanyLink($company));    
}
}
  • You can give your url in $this->setRedirect(JRoute::_($yourUrl)); So you have to replace the JBusinessUtil::getCompanyLink($company)) with your url. – Sudhir Sapkal Jun 12 '18 at 5:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.