ZF2 InputFilter not validating fieldset

2019-06-12 09:02发布

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条回答
聊天终结者
2楼-- · 2019-06-12 09:34

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'
                ),
           ),
        ),
));
}
查看更多
登录 后发表回答