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?
+3
Johannes KlauΓ
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 idnull
or something. - Use form events .
+5
Elnur Abdurrakhimov
source
to share
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);
0
Rainer rainhold
source
to share