ZF-8318: Zend_Form_Element breaks w/Regex validator
Description
Zend_Form_Element
Lines 2046-2049 should be: if (isset($validator['options']['messages']) && is_array($validator['options'])) { $messages = $validator['options']['messages']; unset($validator['options']['messages']); }
currently it lacks is_array($validator['options']). I believe this is the same issue found here: http://old.nabble.com/Zend_Form::addElement-and-a-…
It causes a fatal error when using regex validation, "Cannot unset string offset"
Comments
Posted by Michelangelo van Dam (dragonbe) on 2009-11-19T01:05:44.000+0000
Can you add your code snippet here as well, since I tested this with a simple regex validation without any errors.
This is my testcode:
1 <?php 2 require_once 'Zend/Form.php'; 3 4 class SimpleForm extends Zend_Form 5 { 6 public function init() 7 { 8 $text = new Zend_Form_Element_Text('text'); 9 $text->setLabel('Random text') 10 ->addValidator(array ('regex', true, array ('/[a-z0-9_]+/i'))); 11 $this->addElement($text); 12 } 13 } 14In the mean time, I consider this issue resolved, since Matthew has given a solid answer to the question in the message you provided yourself here.
Posted by Max Summe (msumme) on 2009-11-19T01:20:00.000+0000
'validators' => array(array('Regex', false, '/\d*(.\d{1,2})?/'))
I think I saw somewhere in the documentation this syntax, although I see you need to put the regex in an array now, which I missed yesterday when I was looking at that article.