PrestaShop:提交表单时无效令牌消息


PrestaShop: Invalid token message when submit form

你好,我有这段代码只是显示一个文本区。但是当我提交表单时,我得到一个无效的令牌。你知道吗?

$this->fields_form[0]['form'] = array(
    'tinymce' => true,
    'legend' => array(
        'title' => $this->displayName,
    ),
    'input' => array(
        array(
            'type' => 'textarea',
            'name' => 'legals',
            'rows' => 5,
            'cols' => 60,
            'class' => 'autoload_rte',
            'autoload_rte' => true,
            'lang' => true,
        )
    ),
    'submit' => array(
        'title' => $this->l('Save'),
        'class' => 'button'
    )
);

在生成表单之前,需要以正确的方式初始化一些变量:

$helper = new HelperForm();
$helper->show_toolbar             = false;
$helper->table                    = $this->table;
$helper->module                   = $this;
$helper->default_form_language    = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier    = $this->identifier;
$helper->submit_action = 'submitMyModule'; // Pay attention to this
$helper->currentIndex  = $this->context->link->getAdminLink('AdminModules', false)
                             . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
$helper->token         = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
    'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
    'languages'    => $this->context->controller->getLanguages(),
    'id_language'  => $this->context->language->id,
);
return $helper->generateForm(array($this->fields_form[0]));

这是基本的HelperForm初始化:),但我猜你错过了$helper->token