[英]symfony 2 create custom form how to get form custom element?
$form = $this->createForm(new OrganizationType(), $entity, array(
'action' => $this->generateUrl('_control_organization_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
有定义的动作和方法。 怎么得到这个? 在模板引擎树枝成自定义渲染?
通过致电,
{{ form(form) }}
要么,
{{ form_start(form) }}
使用添加到表单定义中的action
和method
选项值。
从文档中...
另外,请查看文档的“ 构建表单”部分 ,以了解如何通过传递HTML表单
array('form' => $form->createView())
到控制器中的渲染助手。
还...
如果您想在模板中覆盖它们,则必须按照以下步骤将正确的值传递给form()
或form_start()
帮助器,
{{ form(form, {'action': path('target_route'), 'method': 'GET'}) }}
{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
Return your form like this
return $this->render('Your Bundle name: Your controller name : Your twig file', array(
'form' => $form->createView(),
));
And in your twig file get the form like this:
{{ form(form) }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.