Validating Collections in Zend Framework2

2019-09-09 15:24发布

people.. My problem is:

I have a form, with a Collection, so, I setted a CollectionInputFilter to this Collection..

If i send two block of fields (collections) to validate, and one field of one of this block is validated, the same field in the another one block is automatically validated too, even if is wrong or not filled.. I don't know what to do.. I tried a lot of tips.. but, none worked..

Someone can help me? Or faced the same problem?

Here my code:

class ClienteEnderecoFilter extends CollectionInputFilter
{
 public function __construct()
    {
$this->add(array(
            'name' => 'fieldOne',
            'required' => true,
            ));

}
}

If i send two fieldOne and one is filled, the another one is validated too!

1条回答
ら.Afraid
2楼-- · 2019-09-09 16:20

I think you need to set the input filter for each collection item on to the CollectionInputFilter instead of extending it. Like this:

use Zend\InputFilter\InputFilter;

class ClienteEnderecoFilter extends InputFilter
{
    public function __construct()
    {
        $this->add(array(
            'name' => 'fieldOne',
            'required' => true,
        ));

    }
}

$collectionInputFilter = new CollectionInputFilter();
$collectionInputFilter->setInputFilter(new ClienteEnderecoFilter());
查看更多
登录 后发表回答