问题
i use the following fieldset for grouping information:
<input type='text' name='personal[firstname]'>
<input type='text' name='personal[lastname]'>
Now i want to use an InputFilter to validate the form, but nothing happens:
class CustomerFilter extends InputFilter
/**
* Build filter
*/
public function init()
{
$this->add(array(
'name' => 'personal[firstname]',
'required' => true,
'filters' => array(
array('name' => 'StringTrim'),
array('name' => 'StripTags'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'min' => 3,
'max' => 15,
'message' => 'Minimum: 3, Maximum 15 Chars allowed'
),
),
),
));
}
What do i have to change?
EDIT: Finally, i managed it with help of this link:
http://framework.zend.com/manual/2.2/en/modules/zend.form.collections.html
回答1:
No need of array dude,
Remove array[] in zend validation
<input type='text' name='personal[firstname]'>
<input type='text' name='personal[lastname]'>
class CustomerFilter extends InputFilter
/**
* Build filter
**/
public function init()
{
$this->add(array(
'name' => 'personal',
'required' => true,
'filters' => array(
array('name' => 'StringTrim'),
array('name' => 'StripTags'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'min' => 3,
'max' => 15,
'message' => 'Minimum: 3, Maximum 15 Chars allowed'
),
),
),
));
}
来源:https://stackoverflow.com/questions/19563009/zf2-inputfilter-not-validating-fieldset