Exclude Entity fields from update process in Symfony2 forms

I'm in a situation where the Entity edit form is slightly different from the create form. I don't show some of the fields because I don't want them to be edited.

But when I save this form, all un-included fields are set to zero and saved, but I want to exclude those fields from the whole update process.

How can I achieve this?


source to share

2 answers

There are several options:

  • Create a basic edit form type and extend it to add additional fields to create.
  • Keep only one type of form, but add some fields conditionally - that is, only when the object is new. You can get your entity as a form like $options['data']

    and check if its an id null

    or something.
  • Use form events .


Another option is to submit the form instead of handleRequest and pass the second parameter $ clearMissing to false:

$editForm->submit($request->request->get('form_name'), false);




All Articles