Hello Guys,
If you are looking to create form in symfony2 the below code might help you:
1) Open your controller file and function where you would like to define form and add below code with require modification:
//Define in Controller
$filterform = $this->createFormBuilder()
->setMethod('POST')
->add('name', 'text', array('input' => 'text', 'label' =>'Your Name ', 'data' =>''))
->add('Flag', 'hidden', array('attr' => array('value' =>'filter' )))
->add('submit', 'submit', array('label'=>'Refresh', 'attr'=>array('class' =>'btn btn-primary center-block')))
->getForm();
return $this->render('AppCamPaymentsettingBundle:Paymentsetting:paymentSettingsNotCompleted.html.twig', [
'data' => $data,
'filterform' => $filterform->createView(),
]);
2) Now you need to open your view(twig) file and paste the code to define your form:
<div>
{{ form(filterform, {'name': 'filterform'}) }}
{{ form_widget(filterform)}}
{{ form_end(filterform) }}
</div>
0 Comment(s)