ZF2 InputFilter not validating fieldset

天大地大妈咪最大 提交于 2019-12-08 09:25:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!