Creating a simple password confirmation field with Zend_Form

If you creating a user signup form with Zend_Form and need a password confirmation field just use the code below, its very simple but couldn’t find any info on the zend framework site on how to do it


class Application_Form_User extends Zend_Form
    public function init()
        /* Form Elements & Other Definitions Here ... */
        $id = new Zend_Form_Element_Hidden('id');
        // add all your field here....
        $email = new Zend_Form_Element_Text('email');
        $password = new Zend_Form_Element_Password('password');
        /* password confirmation - just set the token section to the password field name */
        $confirmPswd = new Zend_Form_Element_Password('confirm_pswd');
        $confirmPswd->setLabel('Confirm Password:');
        $confirmPswd->setAttrib('size', 35);
        $confirmPswd->addValidator('Identical', false, array('token' => 'password'));
        $confirmPswd->addErrorMessage('The passwords do not match');
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setAttrib('id', 'submitbutton');
             $email, $password, $confirmPswd,

Justin Kelly

Justin Kelly

Data Engineeer, Business Analytics, Web Developer, Library Technology specialising in PHP and Tableau

Based in Melbourne, Australia

Feel free to contact me or _justin_kelly