-1

I would like to use one entity to create two forms in Symfony 3.4.

My User entity contains:

  1. username
  2. password
  3. email
  4. ....

I created one form to connect from "User" entity (username, password) I would like to create another one to create form "Remember me". This new form use only item (email).

How to create two form based in one entity?

Thanks for your help.

v-gael
  • 126
  • 9

1 Answers1

2

The Entity doesn't depend on the form. So you can use your entity in all forms you need. You have to create a new FormType with other fields and use the same Entity to map your fields to.

You can define your Entity when you create a new form.

$myEntity = new MyEntity();

$form = $this->createForm(TestFormType::class, $myEntity);
$form->handleRequest($request);

So you can create many forms and define them for the one entity.

René Höhle
  • 26,716
  • 22
  • 73
  • 82