I have a fieldset with some elements, and a button. When I submit the form I am getting an empty value for the button. How do I tell ZF2 to not include the button in the return data?
//In fieldset
//...other elements
$this->add([
'name' => 'add-question',
'type' => 'button',
'attributes' => [
'onclick' => 'return add_question(this)',
'value' => 'Add Add-On',
'class' => 'add-element text-primary',
],
'options' => [
'label' => '',
'label_options' => [
'disable_html_escape' => true,
],
],
]);
//In controller
if($this->request->isPost()) {
$form->setData($this->request->getPost());
if($form->isValid()) {
var_dump($form->getData());
/*
array (size=12)
//... other elements
'add-ons' => array (size=2)
//... other elements
'add-question' => null
*/
I am aware on the from I can add a validation group, but I can't do that in a fieldset. Also, the form is just an empty form with a submit button in it for re-use - all my form elements are in fieldsets.
$form = new \Application\Form\Form();
with the fieldsets added as needed:$form->add(new \Application\Form\Part1Fieldset()); $form->add(new \Application\Form\Part2Fieldset()); //etc
. This allows me to re-use the fieldsets on other pages in other "forms". - Richard Parnaby-King$form->setValidationGroup($validationGroup)
with a propper nested array with the same structure as you've setup your elements. - Kwidounset($data['add-ons']['add-question'])
before returning data while$data
is$form->getData()
. - unclexo