Problème formulaire avec symfony
Bonjour,
J'ai développé une page contact sous symfony mais lorsque je veux accéder à cette page j'obtiens l'erreur suivante :
Code:
Variable "form" does not exist in frontOfficeBundle:Contact:contact.html.twig
j'ai pas pu la résoudre.
Mon controlleur est le suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| <?php
namespace frontOffice\frontBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use frontOffice\frontBundle\Entity\Contact;
use frontOffice\frontBundle\Form\ContactType;
class ContactController extends Controller
{
public function indexAction()
{
return $this->render('frontOfficeBundle:Contact:contact.html.twig');
}
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()));
}
} |
Mon ContactType est :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| <?php
namespace frontOffice\frontBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class ContactType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nom')
->add('email')
->add('tel')
->add('sujet')
->add('message')
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'frontOffice\frontBundle\Entity\Contact'
));
}
/**
* @return string
*/
public function getName()
{
return 'frontoffice_frontbundle_contact';
}
} |
et ma page est comme ceci
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
{% extends"frontOfficeBundle::layoutheader.html.twig" %}
{% block container %}
<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 </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 </label>
{{ form_widget(form.sujet) }}
</div>
<div class="form-group">
<label>Message </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> |
Mon routing est
Code:
1 2 3
| front_office_send:
path: /Contact
defaults: { _controller: frontOfficeBundle:Contact:send } |