I use Zend\Form\Factory to create forms in zend framework2
$factory = new Zend\Form\Factory();
$factory->createForm(array(
'elements' => array(
array(
'spec' => array(
'name' => 'name',
),
),
),
'input_filter' => array(
'name' => array(
'validators' => array(
// validators for field "name"
),
'filters' => array(
// filters for field "name"
),
),
),
));
You can see that there are filters and validators for field "name". It works. I have the problem if I use fieldsets:
$factory->createForm(array(
'fieldsets' => array(
array(
'spec' => array(
'name' => 'common',
'elements' => array(
array(
'spec' => array(
'name' => 'name',
),
),
),
),
),
),
'input_filter' => array(
'name' => array(
'validators' => array(
// validators for field "name"
),
'filters' => array(
// filters for field "name"
),
),
),
));
In this example input filter doesn`t work. I don't know how to set filters and validators to field "name" in fieldset "common"
This example does not work too:
$factory->createForm(array(
'fieldsets' => array(
array(
'spec' => array(
'name' => 'common',
'elements' => array(
array(
'spec' => array(
'name' => 'name',
),
),
),
'input_filter' => array(
'name' => array(
'validators' => array(
// validators for field "name"
),
'filters' => array(
// filters for field "name"
),
),
),
),
),
),
));
You need to specify 'type' key in input filter when you used fieldset.
If you want to add dynamic validators in the Action (for example validators that are required only when some other fields have a specific value), it is quite a puzzle to apply this when using form collection.
In order to achieve this you should grab the validator chain from the specific element. For each fieldset however, you should first hook in it's own input filter. I would like to share this, because this took me 2 hours to understand ;)
Let's say you have a base form, the base form has a fieldset, and the fieldset has x-elements. The code to add a validator to one of the x-elements requires following chain:
The 2
getInputFilter()
can give you an headache.You have your syntax incorrect, are common and spec supposed to be nested fieldsets or something? Not sure what you are doing there... Try removing the spec part