In zend framework, how do I add an inputfilter for a new form element in a fieldset with the code in the form? In the following case, I've defined a set of common form elements and an inputfilter for those elements in a fieldset class, and add the fieldset to the form. After that, I add one or more new form elements to the fieldset in the form code (I'm doing it in the form and not in the fieldset to prepare to add elements dynamically by form factory). What I'm having trouble with is adding new inputfilter definitions for the additional elements.
in my fieldset:
class myFieldset extends Fieldset implements InputFilterProviderInterface
{
public function init()
{
// add form elements
}
public function getInputFilterSpecification()
{
$inputFilter['myFormElement'] = [
'required' => true,
'filters' => [[ ... ],],
'validators' => [[ ... ],],
'allow_empty' => false,
'continue_if_empty' => false,
];
// more filters
return $inputFilter;
}
}
in my form:
class myForm extends Form
{
public function __construct()
{
// ...
// add elements from fieldset
$this->add([
'name' => 'myFieldset',
'type' => 'Application\Form\Fieldset\myFieldset',
'options' => [
'use_as_base_fieldset' => true,
],
]);
// add new element
$myFieldset = $this->get('myFieldset');
$myFieldset->add([
'name' => 'additionalElement',
'type' => 'Zend\Form\Element\ ... ',
'attributes' => [],
'options' => [],
]);
// update inputfilter
$input = new Input('additionalElement');
$input->setRequired(false);
$currentInputFilter = $this->getInputFilter();
$currentInputFilter->add($input);
$this->setInputFilter($currentInputFilter);
// submit buttons
}
}
In this example, the additional element gets added to the fieldset, but I've got the code wrong to add new definitions to the inputfilter.