eZ Community » Forums » eZ Publish 5 Platform » [EZ 5.3] - Problem exception token...
expandshrink

[EZ 5.3] - Problem exception token Ajax on delete Node

[EZ 5.3] - Problem exception token Ajax on delete Node

Friday 06 June 2014 11:48:41 am - 9 replies

Hello,

I have a problem with ajax request and delete content node on ez 5.3. I have created a service which consists to delete a node. This service is called in a controller like this :

 if ($this->getRequest()->isXmlHttpRequest() && $locationIdRegistration) {
    $serviceCart = $this->get('training_site.cart');
    $serviceCart->removeRegistration($locationIdRegistration);  
} 

The function "removeRegistration" in the service calls the "deleteContent" eZ function like this :

 $this->contentService->deleteContent($contentInfo->contentInfo);

The problem is that the function returns an exception : 

Missing form token from Request .... in /var/www/....../ezpublish_legacy/extension/ezformtoken/event/ezxformtoken.php at line 148

For more details, here is my ajax request : 

 $.ajax({            
    type: 'POST',            
    url: urlAjax,            
    dataType: 'json',            
    success: function (response) {                
        if (response.status == 'success') {                    
            console.log('success');                
        } else {
                    console.log('error');                
        }            
    }        
});

HOWEVER, THE OBJECT IS CORRECTLY DELETED, but i have always the exception.

 

Thanks for your help

Modified on Friday 06 June 2014 11:58:13 am by Clem PERISCOPE

Monday 09 June 2014 10:53:28 am

For more details, there are no exception when the user is not logged (in anonymous).

Tuesday 10 June 2014 10:48:55 am

Hi Clem,

This exception is due to the lack of CSRF certificate. Indeed, if the user is logged in, the presence of this certificate is verified. 

You need to assign a value to the variable "$ _SERVER ['HTTP_X_CSRF_TOKEN']" to bypass this exception for the logged in user. 

Regards,

Tuesday 10 June 2014 4:24:01 pm

Hi Christophe,

I test this solution but I have always an exception. Below, the new exeption :

 Wrong form token found in Request! ... <span>in /var/www/cnpp/ezpublish_legacy/extension/ezformtoken/event/ezxformtoken.php at line 152</span>

 

Another idea maybe ?

Tkx

Tuesday 10 June 2014 5:04:58 pm

You can use the method getToken to have a correct one blunk.gif Emoticon

$_SERVER['HTTP_X_CSRF_TOKEN'] = ezxFormToken::getToken();

Tuesday 10 June 2014 5:08:11 pm

It works perfectly !

Thank you !

Friday 04 July 2014 10:15:13 am

Hello,

The solution works but the admin interface is broken after the request. We always need to clear the cache.

Maybe is there another solution ?

 

Tkx for your help,

Modified on Friday 04 July 2014 10:15:33 am by Clem PERISCOPE

Thursday 31 July 2014 3:07:24 pm

Has someone a solution for this problem ?

 

Tkx for your help,

Thursday 05 March 2015 1:19:21 pm

Hi,

Have you tried with this example:

https://doc.ez.no/eZ-Publish/Tech...4.6/Features/eZ-Form-token-extension

I had the same problem and it working fine now.

Thursday 05 March 2015 6:15:24 pm

Soufian's example (ref: his doc link) is the right way to deal with this.

But make sure you use solution #A when you deal with Platform/Symfony code (or if your unsure), as #B will only work if output is generated by legacy!

Modified on Friday 06 March 2015 12:10:14 pm by André R

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from