0

I am wondering what is the best way to validate multidimensional array using Zend_Validate with Zend_FilterInput.

Here is my current code:

$filters = array(
    'symbol'        => array('StripTags', 'StringTrim'),
    'mode'          => array('StripTags', 'StringTrim'),
);
$validators = array(
    'symbol'        => array('NotEmpty'),
    'mode'          => array('NotEmpty'),
);


$input = new Zend_Filter_Input($filters, $validators, $_POST);

I would like to append here an array, for example name[] array (posting an array with two/three names).

Here is a sample $_POST array:

array(
    'symbol' => 'SD34G',
    'mode'   => 'back',
    'name'   => array(
                       0 => 'Name A',
                       1 => 'Name B',
                       2 => 'Name C'
                )
)

1 Answer 1

2

Ok, I found that I should do it for an array with the same method as for string.

Zend_Filter_Input checks if value is array and does foreach with validating every its element.

So....

$filters = array(
    'symbol'        => array('StripTags', 'StringTrim'),
    'mode'          => array('StripTags', 'StringTrim'),
    'name'          => array('StripTags', 'StringTrim'),
);
$validators = array(
    'symbol'        => array('NotEmpty'),
    'mode'          => array('NotEmpty'),
    'name'          => array('NotEmpty'),
);

;-)

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.