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 
5
  • Can you please add the code from your formType or where you're generating the form? Commented Jul 23, 2014 at 12:58
  • You don't have a field with the name 'email' in the form type. Commented Jul 23, 2014 at 13:03
  • possible duplicate of get value field not declared in nameType.php Commented Jul 23, 2014 at 13:03
  • i don't have field 'email' in my !! form type Commented Jul 23, 2014 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', )); } Commented Jul 23, 2014 at 13:06

1 Answer 1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.