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

时间:2016-08-24 15:57:48

标签: php prestashop

您好我这段代码只显示了一个textarea。但是当我提交表单时,我收到一个无效的令牌。有什么想法吗?

$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'
    )
);

1 个答案:

答案 0 :(得分:1)

在生成表单之前,有一些vars以正确的方式初始化:

$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