-1

I've got a syfmony form with type checkbox or radio. If no checkbox is selected data is not passed to post action.

For example if I have a form with two ChoiceType and i dont select anything from the second one i expect to see in post action something like

form[q1][]:4
form[q2][]:null
form[submit]:

Instead i get in post action:

form[q1][]:4
form[submit]:

I also trying to add in my form:

'required'  => false,

and

'empty_data'  => null,

but still continue having the same issue.
Anyways if i use

$form->handleRequest($request)

i've got empty values as expected but just because there isn't any request with the formName.
This is not what i need because I need to use

$form->submit($request->get($form->getName()), false);

So is there a way to pass to post also empty value? Thanks.

Isky
  • 1,328
  • 2
  • 14
  • 33

1 Answers1

-1

Your question is not a Symfony issue. Instead it is a HTML standard behavior. Only checkboxes and radioboxes that ARE checked will be posted. You can simply set all the fields to FALSE and overwrite them with the $_POST values that exists.duplicate. Another (bad in my opinion) solution is to add hidden fields and update them with javascript when the state of the checkbox changes

Community
  • 1
  • 1
Frank B
  • 3,667
  • 1
  • 16
  • 22