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

Started by Xhanch Studio, March 17, 2012, 05:49:06 AM

previous topic - next topic
Go Down

Xhanch Studio

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:
Code Select
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;:
Code Select
$output .= '<input type="hidden" name="token" value="'.$this->token.'" />';

So it will be look like this:
Code Select
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;
}
Best Regards,
Susanto B.Sc
----------------------------------------------------------------------------
Web development services, WordPress plugin and theme development, PSD to XHTML conversion - http://xhanch.com
Read free manga online - http://authrone.com

Go Up