[英]Onchange in Symfony2 form
This is my input type 这是我的输入类型
->add(‘year’, ChoiceType::CLASS, array(‘choices’ => $array, ‘attr’ => array(‘onchange’ => ‘this.form.submit()’)));
Onchange page is reloading and data is submitted. 正在重新加载Onchange页面并提交了数据。 Then in controller I can access value like this:
然后在控制器中,我可以像这样访问值:
$_POST[‘year’].
The thing is I would like to get $_POST in symfony's way: 事情是我想以symfony的方式获得$ _POST:
$form[‘year’]->getData();
I don't know why only $_POST['year'] works and no result with $form['year']->getData(). 我不知道为什么只有$ _POST ['year']有效,而$ form ['year']-> getData()没有结果。
You can use for POST request : 您可以使用POST请求:
$request->request->get('year');
For GET request: 对于GET请求:
$request->query->get('year');
For FILE queries: 对于FILE查询:
$request->files.
You can get a single item from the form data like; 您可以从表单数据中获取单个项目,例如;
$year = $form->get('year')->getData();
In this example 'year' is the name given to the field you are asking for (as per your form builder) 在此示例中,“年份”是您要查询的字段的名称(根据您的表单生成器)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.