Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:21:48+00:00 2026-06-13T04:21:48+00:00

I am a newbie in zf, recently I m making a register form using

  • 0

I am a newbie in zf, recently I m making a register form using zend_dojo_form and there are two passwordtextbox elements, which u know, one is for entering password and the other is to confirm the former one, then I using the validator ‘token’ but failed, here is part of my code.

$this->addElement('PasswordTextBox','password',array(
            'label'=>'password:',
            'required'=>true,
            'trim'=>true,
            'regExp'=>'^[a-z0-9]{6,18}$',
            'invalidMessage'=>'password should be 6-18',
            'Decorators' => array(
                'DijitElement',
                'Errors',
                array(array('data'=>'HtmlTag'),array('tag'=>'td','align'=>'left')),
                array('Label',array('tag'=>'td')),
                array(array('row'=>'HtmlTag'),array('tag'=>'tr','align'=>'right'))
                )
            )
        );
    //$this->addElement($password1);

    $this->addElement('PasswordTextBox','password2',array(
        'label'=>'confirm password:',
        'required'=>true,
        'trim'=>true,
        //'regExp'=>'^[a-z0-9]{6,18}$',
        'validators'=>array(array('identical',false,array('token'=>'password'))),
        'invalidMessage'=>'the password you enter not the same',
        'Decorators' => array(
            'DijitElement',
            'Errors',
            array(array('data'=>'HtmlTag'),array('tag'=>'td','align'=>'left')),
            array('Label',array('tag'=>'td')),
            array(array('row'=>'HtmlTag'),array('tag'=>'tr','align'=>'right'))
            )
        )
    );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:21:49+00:00Added an answer on June 13, 2026 at 4:21 am

    Here’s a sample that should be functional:

    class Application_Form_Register extends Zend_Dojo_Form {
    
        public function init() {
                $this
                                ->setOptions(array('name' => 'registerForm'))
                                // username
                                ->addElement('TextBox', 'first_name', array(
                                        'filters' => array('StringTrim', 'StringToLower'),
                                        'id' => 'name_register',
                                        'required' => true,
                                        'label' => 'Fornavn(e):',
                                ))
                                ->addElement('TextBox', 'last_name', array(
                                        'filters' => array('StringTrim', 'StringToLower'),
                                        'id' => 'surname_register',
                                        'label' => 'Efternavn:',
                                ))
                                ->addElement('ValidationTextBox', 'email', array(
                                        'filters' => array('StringTrim', 'StringToLower'),
                                        'validators' => array(
                                                'EmailAddress',
                                                array('StringLength', false, array(3, 60)),
                                        ),
                                        'regExp' => "^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$",
                                        'id' => 'email_register',
                                        'required' => true,
                                        'label' => 'E-mail:',
                                ))
                                //password
                                ->addElement('PasswordTextBox', 'password', array(
                                        'filters' => array('StringTrim'),
                                        'validators' => array(
                                                'Alnum',
                                                array('StringLength', false, array(6, 20)),
                                        ),
                                        'regExp' => "^([a-zA-Z0-9_\-!-=]){4,32}$",
                                        'tooltipPosition' => 'above',
                                        'invalidMessage' => 'Krav til password: mellem 4 og 32 i længde og kun karakterer som tal, bogstaver eller blandt [ _-!"#%&/()=] er tilladt',
                                        'id' => 'password_register',
                                        'onKeyDown' => 'arguments[0].keyCode == dojo.keys.ENTER && application.submitRegistration(dijit.byId(\'registerForm\'));',
                                        'required' => true,
                                        'label' => 'Password:',
                                ))
                               ->addElement('PasswordTextBox', 'password_confirm', array(
                                        'filters' => array('StringTrim'),
                                        'validators' => array(
                                                'Alnum',
                                                array('StringLength', false, array(6, 20)),
                                        ),
                                        'id' => 'passwordconfirm_register1',
                                        'onKeyDown' => 'arguments[0].keyCode == dojo.keys.ENTER && application.submitRegistration(dijit.byId(\'registerForm\'));',
                                        'required' => true,
                                        'label' => 'Gentag password:',
                                ))
    
                               ->addElement('PasswordTextBox', 'password_confirm', array(
                                        'filters' => array('StringTrim'),
                                        'validators' => array(
                                                'Alnum',
                                                array('StringLength', false, array(6, 20)),
                                        ),
                                        'id' => 'passwordconfirm_register2',
                                        'onKeyDown' => 'arguments[0].keyCode == dojo.keys.ENTER && application.submitRegistration(dijit.byId(\'registerForm\'));',
                                        'required' => true,
                                        'label' => 'Gentag password:',
                                ))
                                ->addElement('Hidden', 'action', array(
                                        'id' => 'action_register',
                                        'value' => 'register',
                                ))
                                ->addElement('Button', 'foo', array(
                                        'id' => 'foo_register',
                                        'onClick' => 'application.submitRegistration(dijit.byId(\'registerForm\'))',
                                        'label' => 'Register'
                                                )
                );
                $this->_decorate();
    
        }
        // renders nulled empty labels and adds classnames, related to element name
        protected function _decorate() {
                $this->setDecorators(array(
                        'FormElements',
                        array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form_contents')),
                        'DijitForm'
                ));
    
                foreach ($this->getElements() as $el) {
    
                        $el->addDecorator('HtmlTag', array('tag' => 'div', 'class' => $el->getName() . '-wrap'));
                        if ($el->helper == 'Button')
                                continue;
                        else if (strlen(trim($el->getLabel())) == 0)
                                $el->addDecorator('Label', array('tag' => null));
                        else
                                $el->addDecorator('Label', array('tag' => 'div', 'class' => $el->getName() . '-label'));
                }
        }
    }
    

    Focusing on the two password fields – in terms of what makes clientside validation tick, lets filter out the Zend_Form_Element attributes:

     ->addElement('PasswordTextBox', 'password_2_', array(
           // strictly serverside, only accepts alphanumerical pwds lengths 6 through 20
           'validators' => array(
               'Alnum',
               array('StringLength', false, array(6, 20)),
           ),
           // widget id
           'id' => 'passwordconfirm_register1',
           // both client-/server-side - triggers 'emptyMessage' validation
           'required' => true,
           // runs with the form.validate() and events onblur, oninit, onkeypress
           // if ! dijit.get("value").match(dijit.regExp) show 'invalidMessage'
           // this example matches the serverside reqs
           'regExp' => "^([a-zA-Z0-9_\-!-=]){6,32}$",
           // shown with form.validate(), dijit.validate() and input.blur() if regExp is not  a match against value
           'invalidMessage' => 'Password musts: 6 to 32 chars and only numbers, letters or amongst [ _-!"#%&/()=]',
      ))
    

    And a second pwd field, same attributes but with a different validator

     ->addElement('PasswordTextBox', 'password_2_', array(
           // strictly serverside, only accepts alphanumerical pwds lengths 6 through 20
           'validators' => array(
               array('identical',false,array('token'=>'password'))
           ),
           // widget id
           'id' => 'passwordconfirm_register2',
           'required' => true,
           // in theory, we would define 'validator' in programmatic construct of
           // the validationtextbox. but this will not work with the way Zend handles dojo
           // 'validator' => 'function(value, constraints) { return "BAD PRACTICE" }'
      ));
      // add javascript code to run onload and to extend the 'register2' properly
      $this->getElement()
          ->getView()
          ->headScript()
          ->appendFile($baseUrl . '/js/Validator.js');
    

    By now, only ‘required’ is validated clientside in the passwordconfirm_register2 widget. Lets fix in what markup factory does in regards to ‘bad practice’ in the above lines. Remove that line and add the javascript code instead, containing:

    // file: baseUrl/js/Validator.js
    dojo.addOnLoad(function() {
      dijit.byId('passwordconfirm_register2').validate = function(value, constraints) {
    
         if(dijit.byId('passwordconfirm_register1').get("value") != value) {
                this.invalidMessage = "Passwords are not identical";
                return false;
         }
    
         return true
    
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a complete newbie when it comes to OCaml. I've only recently started using
I'm a newbie to Linux systems and recently I started using Ubuntu 10.04. When
I started using Hibernate recently and I'm still a newbie, however, the error I'm
I am a php newbie and I am using MAC OS. I recently set
I'm a bit of a jQuery newbie, only recently started. I am using http://flesler.blogspot.com.au/2007/10/jqueryscrollto.html
I'm a android newbie. Recently I created a activity which has a HorizontalScrollView at
Newbie in testing. I generated a test case using Selenium, and then exported it
Newbie question: There are three types of Asp.Net controls : HTML server controls, Web
Recently moved from svn to git, pardon my newbie question. In our release process,
i'm a newbie to jquery... i just recently discovered the jquery UI library. what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.