Workaround for broken macro {form}

If you ever tried changing your form from POST to GET with $form->setMethod(‘get’) and then render it with macro {form} … {/form} I’m sure you discovered that your submission callback doesn’t trigger. Apparently it’s difficult to resolve this in a clean way so until the Nette team finds a solution you’ll have use some sort of a hacky workaround.

The thing is to add one hidden form item that eventually triggers the form submission callback:

  2. {form signForm}
  3.    {var $signalElement = Html::el(‘input’, array(
  4.      ‘type’ => ‘hidden’,
  5.      ‘name’ => Presenter::SIGNAL_KEY,
  6.      ‘value’ => ‘signForm’.Presenter::NAME_SEPARATOR.’submit’
  7.   ))}
  8.   {$signalElement}
  9. {/form}


Leave a Reply