0

can somehow unchecked checkboxes be included when I have a form with a dynamic number of checkboxes (name='golyPenalta[]') and in submit I get them using $form->getHttpData($form::DATA_TEXT, "golyPenalta[]"); ? Only the ones that have been checked are placed in the field and have their own order, so I do not know which penalty belongs to which goal:

golyCas => array (3)
   0 => "55" (2)
   1 => "60" (2)
   2 => "70" (2)
golyPenalta => array (2)
   0 => "on" (2)
   1 => "on" (2)   // <- this should be part of third goal so index should be 2

I already tried to do it with $form->getHttpData($form::DATA_TEXT | $form::DATA_KEYS, "golyPenalta[]"); but with no luck. The dump above is from the dump of $form in attribute httpData.

Johny12369
  • 75
  • 7

2 Answers2

0

Unfortunately no, unchecked checkboxes aren't even sent in POST data in http. You have to define the elements in nette and then use $form->getValues() to have them included. If you add them just on the client side, the server has no chance to know they exist.

Matěj Koubík
  • 1,087
  • 1
  • 9
  • 25
0

I eventually made it with specific key in input name name='golyPenalta[key]' when I create dynamic numbers of this field. It can be done either way by Nette form name='golyPenalta[{key}]' or I create it by JavaScript in for loop when I get the number of fields I have to create like this name='golyPenalta[$i]'.

In form submit I use $form->getHttpData($form::DATA_TEXT | $form::DATA_KEYS, "golyPenalta[]") to persist these keys.

Johny12369
  • 75
  • 7