Posted on Leave a comment

Updating Select Options and InArray Validator in Zend Form

Zend Framework Logo

When using Zend_Form’s multi-select with dynamically set options you need to make sure to update your options and the InArray validator accordingly when validating data using form->isValid().

In order to update selection options and update the InArray validator we need to first set the options, remove the currently set InArray validator and set it with the desired valid options, as shown below:

$options = array(); // ...

  ->addValidator(new Zend_Validate_InArray(array_keys($options)));

That’it it.