Using Zend_Validate_Identical in Form Validation

I'm trying to use the 'Identical' validator to validate whether two passwords are the same in my registration form, but it keeps trying to validate against the actual word I enter for the token rather than the form element that I want to validate against. Code looks like this: (This is my form model constructor..)

    $password = new Zend_Form_Element_Password('password');
    $password->addValidator('Regex',false,array('pattern' => '/^.*(?=.{6,20})(?=.*[\d])(?=.*[a-zA-Z])/'))

    $password2 = new Zend_Form_Element_Password('password2');
    $register = new Zend_Form_Element_Submit('register');

                                       array('viewScript' => '_form_registration.phtml'))  


Instead of validating against the form element called 'password' it keeps trying to match against the actual string 'password'

The work around I have is that I create a validator after the data has been posted to the controller, and validate against the post data, but if there is any more modular way to do this (AKA leaving the logic within the form constructor) I would love to know.

Thank you in advance


Are you outputting your form correctly?

I see that the decorator you're using is ViewScript so I'm guessing that you are coding the form's html yourself in some other script.

If so, are you following the Zend way of assigning names and id values to your elements? If you aren't, when you pass in the values to your form the context might not be set up correctly and it won't find the 'password' element that you need to check against.

My suggestion right now is to ouput the form using the form default decorators and look at how the ids and names look for the elements. Then, try to copy those names in the form.phtml that you're using.

After add the Identical Validator on your 'password2' element.

Try to overload isValid() function into your Form Object like this:

    public function isValid ($data)
             ->setMessage('Passwords don\'t match.');
        return parent::isValid($data);

Need Your Help

cython convert void* back to python obj

python c cython

Got error message while want to convert void* back to python obj.

Gesture detection on Fragment

android android-fragments gesture gesture-recognition

I have an Activity which holds a single Fragment:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.