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:

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

Tags:

Leave a Reply