3

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 
user3816170
  • 319
  • 12
  • 20
  • Can you please add the code from your formType or where you're generating the form? – KhorneHoly Jul 23 '14 at 12:58
  • You don't have a field with the name 'email' in the form type. – qooplmao Jul 23 '14 at 13:03
  • possible duplicate of [get value field not declared in nameType.php](http://stackoverflow.com/questions/18745880/get-value-field-not-declared-in-nametype-php) – KhorneHoly Jul 23 '14 at 13:03
  • i don't have field 'email' in my !! form type – user3816170 Jul 23 '14 at 13:05
  • 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 Jul 23 '14 at 13:06

1 Answers1

5

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();
Community
  • 1
  • 1
KhorneHoly
  • 4,666
  • 6
  • 43
  • 75