Search code examples
formscheckboxnette

Nette getHttpData include of unchecked checkboxes


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.


Solution

  • 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.