I need to disable / re-enable form fields depending on values of a given field. To achieve it, I use a listener on the onPreSubmit event. Then, if a field should be disabled, it is added to the form again like
$form->add('name', 'text', array("disabled" => "disabled");
This work great in one sense: if a field was enabled but should be disabled, then the result is OK. In the other sense, if a field was disabled then this field is not sent. In the listener, the field is enable but on the final result the intial value isn't there anymore.
I assume that, because the field was disabled, it wasn't sent, so Symfony considered it has a null value. From a listener on preSubmit or Submit events, if I do:
$event->getData()
Then all fields that are in the form but not in the POST data are set to null. Is there no way to activate simply the field, keeping the initial value ? Or to not consider the value of missing fields ?