3
votes

How can i add text fields in my form knowing that it does not exist in my entity!!

i have this in my twig :

 <form action="{{ path('add_conge') }}" method="post">
<h1>{{ 'Envoyer une demande de cong&eacute;'}}</h1>

 <div>
{{ form_errors(form.email) }}
{{ form_label(form.email, 'Email Collaborateur:') }}
{{ form_widget(form.email) }}
</div>

<div>
{{ form_errors(form.dateDepart) }}
{{ form_label(form.dateDepart, 'Date depart:') }}
{{ form_widget(form.dateDepart) }}
</div>
//...

and i get this exception:

 Method "email" for object "Symfony\Component\Form\FormView" does not exist in SqliGestionCongeBundle:Default:add.html.twig 
1
Can you please add the code from your formType or where you're generating the form?KhorneHoly
You don't have a field with the name 'email' in the form type.qooplmao
i don't have field 'email' in my !! form typeuser3816170
i have juste this in my Form Type: public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('dateDepart', 'date', array( 'input' => 'datetime', 'widget' => 'choice', )) ->add('dateRetour', 'date', array( 'input' => 'datetime', 'widget' => 'choice', )) ->add('nbreJour') ->add('justificatif') ->add('dateDemande', 'date', array( 'input' => 'datetime', 'widget' => 'choice', )); }user3816170

1 Answers

5
votes

As said in this Question you don't have that field in your form type.

To add a field that's not mappend with the entity/formType you need to do the following:

//where you're creating your form with the formbuilder
->add("email", "email", array("mapped"=>false);

This will add a field to your form that is not related with the entity.

To receive the data from it just do this in the controller/action where you're handling the form:

$form->get("email")->getData();