I'm using a Symfony 2 in a project, and I need to have dependent selects in my form. Currently I'm following this tutorial showmethecode.es and its working.
But I'm also using options groups in the selects, and I really need to add some extra variables and some logic in the client side.
My question is, how can I add variables to a form (in the client side), and join them in a Type class.
Either you read up on Custom Form Field types and Data transformers:
Or you create the form yourself and get the data from the request in the send action. You should however create a CSRF Token when creating the form and check it when submitting the form:
$this->get('security.csrf.token_manager');
//Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider
$token = $csrf->getToken("bundlenamespace_formname");
And validate it like so:
$this->get('security.csrf.token_manager')->isTokenValid($request->get('_token', ''));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.