Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create form in Symfony2

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 262
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: