ZF2 InputFilter未验证字段集

时间:2013-10-24 10:10:28

标签: validation zend-framework2 fieldset input-filter

我使用以下字段集来分组信息:

<input type='text' name='personal[firstname]'>
<input type='text' name='personal[lastname]'>

现在我想使用InputFilter来验证表单,但没有任何反应:

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'
                    ),
               ),
            ),
    ));
}

我需要改变什么?

编辑: 最后,我借助此链接管理它:

http://framework.zend.com/manual/2.2/en/modules/zend.form.collections.html

1 个答案:

答案 0 :(得分:2)

不需要数组老兄,

在zend validation中删除array []

<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'
                ),
           ),
        ),
));
}