简体   繁体   中英

Joomla: error while saving form in custom view

I have created a custom component with form to update prices of four product to be displayed on frontend.

My main controller code is here:

public function display($cachable = false, $urlparams = false) {

    require_once JPATH_COMPONENT.'/helpers/calculator.php';

    $view       = JFactory::getApplication()->input->getCmd('view', 'pricetable');
    $layout     = JFactory::getApplication()->input->getCmd('layout', 'edit');

    JFactory::getApplication()->input->set( 'layout', $layout );
    JFactory::getApplication()->input->set('view', $view);
    JFactory::getApplication()->input->set('id', 1);

    parent::display($cachable, $urlparams);
    return $this;
}

id is set to 1 so it loads only first row from database.

code for pricetable container is:

function __construct() {
    $this->view_list = 'pricetable';
    parent::__construct();
}

Now in admin backend the form is loaded as desired with the first row of data. When I try to save the form it is redirected to administrator/index.php?option=com_calculator&view=pricetable and error is:

Error: You are not permitted to use that link to directly access that page (#1).

my form action is:

<?php echo JRoute::_('index.php?option=com_calculator&task=pricetable.edit&id='.(int) $this->item->id); ?>

Please suggest where I am doing wrong. It is third day I'm scratching my head. :(

You can do updating actions (or calling them) inside your code whenever it is. New instance or update new - just add one more if in code and hidden input on form. For example:

<input type="hidden" name="task" value="update" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM