Jump to content

[solved] How do I create an admin link with valid security token?


Recommended Posts

I'm writing a module for Prestashop 1.5, and have a table with links to some orders, in the backend. I'm trying to generate a link to an order item, but when I click the link, I get a screen telling me:

 

Invalid security token

 

In my template I have the following snippet:

 

 

<a href="{$script_name}?controller=adminorders&id_order={$p.id_order}&vieworder&token={$token}">{$p.id_order}</a>

 

When I click the I understand the risks.. warning, the page displays fine, and loads the order appropriately. I just want to get rid of the token error message.

 

How do I generate a proper token for the URL query string?

Link to comment
Share on other sites

Nothing significant, I tried another token from the previous page, but it obviously needs to be generated. Pretty certain it's got to do with Tools::getAdminToken().

 

you can also use this: {$smarty.get.token}

Link to comment
Share on other sites

For my ajax product updates I use these tokens.. maybe they get you in the right direction

 

To open a products page logged in I use

$tokenProducts = Tools::getAdminToken('AdminProducts'.intval(Tab::getIdFromClassName('AdminProducts')).intval($cookie->id_employee));

 

To send a validation token via ajax to a module I use:

 $token = Tools::getAdminToken('AdminModules'.intval(Tab::getIdFromClassName('AdminModules')).intval($cookie->id_employee));

 

Best regards, trip

Edited by Trip (see edit history)
  • Like 3
Link to comment
Share on other sites

  • 1 year later...

Great information! Thanks for it.

Now i can go ahead and mark this thread as solved

 

regards

What should i do if i want to link any order page to my module. I means i set link for each order in my module and set token using both Tools::getAdminToken('AdminOrders'.intval(Tab::getIdFromClassName('AdminOrders')).intval($cookie->id_employee)) and Tools::getAdminToken('MymoduleClass'.intval(Tab::getIdFromClassName('MymoduleClass')).intval($cookie->id_employee)) but each time i get error INVALID SECURITY TOKEN

Link to comment
Share on other sites

×
×
  • Create New...