I'm creating a simple contact component in Joomla 3.3 (which is called Contact Pay).

I created a 'message' and a 'messages' view in the back-end, with associated models and controllers. 'message' is a JForm form, and 'messages' is the list view. Everything works fine there.

However in the front-end I only have a message view, for site visitors to send message. I use the same back-end model in the front-end, using

$controller->addModelPath( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_contactpay'.DS.'models' );

in the component entry file.

I simply copied the form XML file (message.xml) from the back-end, removed a few fields, and used it for the front-end. I output the form with the following layout file:

<form action="<?php echo JRoute::_( 'index.php?option=com_contactpay&task=message.save'); ?>"
      method="post" id="contactpay-message-form" class="form-validate form-horizontal" enctype="multipart/form-data">


        <?php foreach( $this->form->getFieldset('message_fields') as $field ) : ?>
            <div class="control-group">
                <div class="control-label">
                    <?php echo $field->label; ?>
                <div class="controls">
                    <?php echo $field->input; ?>
        <?php endforeach; ?>


    <div class="form-actions">
        <button type="submit" class="btn btn-primary validate"><?php echo JText::_('JSUBMIT');?></button>
        <a class="btn" href="<?php echo JRoute::_('');?>" title="<?php echo JText::_('JCANCEL');?>"><?php echo JText::_('JCANCEL');?></a>
        <input type="hidden" name="option" value="com_contactpay" />
        <input type="hidden" name="task" value="message.save" />
        <?php echo JHtml::_('form.token');?>

When a use fills out the form on the front-end it is saved to the database as it should be.

The Problem

The problem is that after the form is submitted it redirects to a 'messages' view which doesn't exist on the front-end, so I get the following error:

500 View not found [name, type, prefix]: messages, html, contactpayView 

I tried controlling the redirect in the message controller which extends JControllerForm using the following code in the constructor:

$this->setRedirect( JRoute::_( 'index.php?option=com_contactpay&view=message' ));

However, this produces the same results.

How do control the component redirect?

3 Answers 3


The redirect is likely getting overridden by the save function in your controller. You should be able to override the redirect with the method that you listed, we just need to get it in the right spot.

It looks like you should have a message controller on the front end. If you don't have a save function within this controller, add one like so:

public function save($key = null, $urlVar = null)
    $return = parent::save($key, $urlVar);
    $this->setRedirect( JRoute::_( 'index.php?option=com_contactpay&view=message' ));
    return $return;

This utilizes the existing save method in JControllerForm that loads the model and saves the form, but it makes sure that your redirect overrides the default redirect to the list view.


You should have a file called components/com_contactpay/controller.php This is the primary controller for your component. The class within the file should be called ContactPayController.

Add the following construct function. It should look something like this.

class ContactPayController extends JControllerLegacy {

    public function __construct(){
        if (JFactory::getApplication()->input->get('view') == "messages"){
        } else {

That should handle the redirect for you before the controller looks for the messages view.


Just declare a $view_list variable at your JControllerForm equal to your prefer view name (view folder normally)

protected $view_list = 'message';

and all your form event will redirect to it, unless you specifiably declare equivalent functions as David Fritsch suggests! Best solutions are the simplest!:)

Your Answer

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

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