I have several times experienced an awkward, inconsistent and annoying behaviour in Symfony 2 forms validation. Without any reason, all forms sometimes all fail to validate (on call of $form->isValid()
after $form->handleRequest($this->getRequest());
). So far I have seen it only in prod environment.
What makes me say it is awkward and inconsistent is that it often work just fine, but sometimes don't. The only way I have found to make it work again is to clear the cache or to simply wait.
I have tried to debug the forms when it fails, but I haven't been able to get any error from the form (empty $form->getErrors()
, empty $form->getErrors(true)
, no errors in $form->getErrorsAsString()
).
Do you have any idea of what could be the reason of this problem? Could it be because of the CSRF token? The thing is that I haven't activated the use of the token and didn't manually put it in the forms. But even when I tried to add form_rest
in the view when having the issue I still had the issue.
I really worry because it is unpredictable and it has a massive impact. I can't reproduce it at will and I don't know for how long the "fix" will work. Clearing the cache sometimes work only for a single form submit. Today, it started working again while I was printing various var_dump, meaning without having changed anything. The code itself works, it can't be an issue with the model/entity because a same form can either fail or work.