XHanch Studio Log in | Register | Cart

Forum

[Troubleshoot] &quo...
 
Notifications
Clear all

[Troubleshoot] "Invalid security token" when filtering and navigating on Prestashop admin/backend

1 Posts
1 Users
0 Likes
1,906 Views
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

You may encounter similar problem/issue with Prestashop by getting Invalid security token warning/message when doing certain activities on admin/backend area, such as:

  • Filtering products, orders, and others
  • Navigating between pages on catalog, order manager, and others

To solve this issue, you can add the hidden token by editing classes/AdminTab.php. In that file, you can find this function:

public function displayForm($isMainTab = true)
{
    global $cookie;
   
    $allowEmployeeFormLang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
    if ($allowEmployeeFormLang && !$cookie->employee_form_lang)
        $cookie->employee_form_lang = intval(Configuration::get('PS_LANG_DEFAULT'));
    $useLangFromCookie = false;
    $this->_languages = Language::getLanguages();
    if ($allowEmployeeFormLang)
        foreach ($this->_languages AS $lang)
            if ($cookie->employee_form_lang == $lang['id_lang'])
                $useLangFromCookie = true;
    if (!$useLangFromCookie)
        $this->_defaultFormLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
    else
        $this->_defaultFormLanguage = intval($cookie->employee_form_lang);
   
    $output = '
    <script type="text/javascript">
        $(document).ready(function() {';
    // If current tab is main/first tab
    // Otherwise form_id_language has already been defined
    if ($isMainTab)
        $output .= '
            id_language = '.$this->_defaultFormLanguage.';';
    $output .= '   
            languages = new Array();';
    foreach ($this->_languages AS $k => $language)
        $output .= '
            languages['.$k.'] = {
                id_lang: '.(int)$language['id_lang'].',
                iso_code: ''.$language['iso_code'].'',
                name: ''.htmlentities($language['name'], ENT_COMPAT, 'UTF-8').''
            };';
    $output .= '
            displayFlags(languages, id_language, '.$allowEmployeeFormLang.');
        });
    </script>';
    echo $output;
}

You just need to add the following code code right before echo $output;:

$output .= '<input type="hidden" name="token" value="'.$this->token.'" />';

So it will be look like this:

public function displayForm($isMainTab = true)
{
    global $cookie;
   
    $allowEmployeeFormLang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
    if ($allowEmployeeFormLang && !$cookie->employee_form_lang)
        $cookie->employee_form_lang = intval(Configuration::get('PS_LANG_DEFAULT'));
    $useLangFromCookie = false;
    $this->_languages = Language::getLanguages();
    if ($allowEmployeeFormLang)
        foreach ($this->_languages AS $lang)
            if ($cookie->employee_form_lang == $lang['id_lang'])
                $useLangFromCookie = true;
    if (!$useLangFromCookie)
        $this->_defaultFormLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
    else
        $this->_defaultFormLanguage = intval($cookie->employee_form_lang);
   
    $output = '
    <script type="text/javascript">
        $(document).ready(function() {';
    // If current tab is main/first tab
    // Otherwise form_id_language has already been defined
    if ($isMainTab)
        $output .= '
            id_language = '.$this->_defaultFormLanguage.';';
    $output .= '   
            languages = new Array();';
    foreach ($this->_languages AS $k => $language)
        $output .= '
            languages['.$k.'] = {
                id_lang: '.(int)$language['id_lang'].',
                iso_code: ''.$language['iso_code'].'',
                name: ''.htmlentities($language['name'], ENT_COMPAT, 'UTF-8').''
            };';
    $output .= '
            displayFlags(languages, id_language, '.$allowEmployeeFormLang.');
        });
    </script>';
    $output .= '<input type="hidden" name="token" value="'.$this->token.'" />';
    echo $output;
}
 
Posted : 17/03/2012 12:49 pm
Share:

× Close Menu