Closed
Description
Hello,
I am trying to submit my form via ajax (using jQuery latest version) like this :
var $form = $("form#search");
var values = $form.serialize();
jqhr = $.post(
$form.attr("action"),
values,
function(data) {
console.log(data);
},
"json"
);
in dev mode, i received my data, it is OK.
But in production mode i have an "invalid token error " :
Le jeton CSRF est invalide. Veuillez renvoyer le formulaire
My controller :
public function ajaxFormSubmitAction(Request $request)
{
if (!$request->isXmlHttpRequest())
throw new \HttpRequestMethodException();
$form = $this->createForm(new SearchType(), new Search();));
if ($request->isMethod('POST'))
{
$form->submit($request);
if ($form->isValid())
{
return New JsonResponse(array( "status" => true,
"count" => 123));
}
// => reached in production mode but not in dev mode !!!
print_r($form->getErrors());
}
return New JsonResponse(array( "status" => false,
"count" => 0));
}
I don't understand why CSRF validation is OK in DEV mode and not in PRODUCTION mode ...! strange !!??
Sorry for posting this issue here but i did'nt find any other solution on forums etc. so wondering if it is a Symfony2 Form / CRSF issue...
Note : using Symfony2.4 beta2 / PHP 5.5.5 / Apache 2.4
Metadata
Metadata
Assignees
Labels
No labels