0

I've searched internet and there is no official documentation for applying input filters to arrays in ZF3.

I have seen answers for ZF2, Zend Framework 2 filter / validate array of contents

Can anyone help out how to apply input filters to array of input.

This is my form class

class ContactForm extends Form
{
 public function __construct($name = null)
{
    // we want to ignore the name passed
    parent::__construct("contactForm");
    $this->addInputFilters();
}

public function init()
{
    $this->add([
        "name"                       => "Type[]",
        "type"                       => "text",
        "attributes"                 => [
            "class"                  => "form-control",
        ],
    ]);
}
private function addInputFilters() {
    $inputFilter->add([
        "name"                       => "Type[]",
        "required"                   => true,
        "filters"                    => [],
        "validators"                 => [
            [
                "name"               => "StringLength",
                "options"            => [
                    "min"            => 3,
                    "max"            => 100,
                ],
            ],
        ],
    ]);
}
2
  • (new InputFilterClass())->setData(['dataKey'=>'dataValue'])->isValid() ? Commented Dec 13, 2018 at 12:41
  • Either update or delete the question please. Flagged for closing. Commented Jan 16, 2019 at 8:08

1 Answer 1

0

This page has the answer for you https://olegkrivtsov.github.io/using-zend-framework-3-book/html/en/Collecting_User_Input_with_Forms/Adding_Form_Filtering_and_Validation_Rules.html .

The first difference I can see is the method name that is not addInputFilters but addInputFilter, without 's'.

Also within addInputFilter you did not get the form input filter with

$inputFilter = $this->getInputFilter();

infact in you example you are calling 'add' to an undefined variable actually, but perhaps your posted example is not the ful code.

Also, if you want to validate collection ( wich kind of data is going to validate 'Type[]'? ), use Collection input filter, and assign to it an input filter to validate each entry.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.