php - form in symfony does not exist -


i'm testing simple page of contact symfony when want display contact.html.twig doesn't appear , have error form not exist

there controller

 public function sendaction() {    $contact = new contact();     $form = $this->createform(new contacttype(),$contact);     $_request = $this->getrequest();     if($_request->ismethod('post')){        $form->bind($_request);         if($form->isvalid()){             $contact = $form->getdata();             $em = $this->getdoctrine()->getmanager();            $em->persist($contact);            $em.flush();             return $this->redirect($this->generateurl('front_office_send'));        }    }     return $this->render('frontofficebundle:contact:contact.html.twig', array('form' => $form->createview()));  } 

and page contact.html.twig:

{% extends"frontofficebundle::layoutheader.html.twig" %} {% block container %} <form id="form" class="form-light mt-20" role="form" method="post" action="{{ path('front_office_send') }}">                          <div class="form-group">                             <label>nom</label>                             {{form_widget(form.nom)}}                          </div>                         <div class="row">                             <div class="col-md-6">                                 <div class="form-group">                                     <label>adresse électronique &nbsp;</label>                                     {{ form_widget(form.email) }}                                  </div>                             </div>                             <div class="col-md-6">                                 <div class="form-group">                                     <label>téléphone</label>                                     {{ form_widget(form.tel) }}                                  </div>                             </div>                         </div>                         <div class="form-group">                             <label>sujet &nbsp;</label>                             {{ form_widget(form.sujet) }}                          </div>                         <div class="form-group">                             <label>message&nbsp;</label>                             {{ form_widget(form.message) }}                          </div>                         <div class="row">                             <div class="col-md-6">                                 <button type="reset" class="btn btn-light">annuler</button>                             </div>                             <div class="col-md-6">                                  {{ form_widget(form._token) }}                                 <button  type="submit" class="btn btn-base btn-icon btn-icon-right btn-fly pull-right">                                     <span>envoyer message</span>                                 </button>                             </div>                         </div>                     </form> 

i have routing:

front_office_send:  path:     /contact  defaults: { _controller: frontofficebundle:contact:send } 

the error begin in line {{form_widget(form.nom)}} variable form not exist.

if put

{{ form_widget(form) }}  

it show whole form,

if put

{{ form_widget(form.something) }}  

you mean field something, cannot that, have on first way.

if want show 1 field (like think want...) should form_row

{{ form_row(form.nom) }} 

here have documentation

http://symfony.com/doc/current/book/forms.html#rendering-a-form-in-a-template


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -