[英]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.