How to use multiple validators in zend form ??


Use of multiple validation in zend form >>

First basic how to add validator to any filed..

$password = new Zend_Form_Element_Password('password'); $passsword->setLabel('Password :') ->setRequired(true) ->addValidator('NotEmpty') ->addValidator('Digits');
So, on this we use two validator one is 'NotEmpty' and second is 'Digits'.

Now problem comes when we submit we got both message together which not good. see in below images.


So, now solution is here..

just use custom modification you can write custom message using setMessage..

$notEmpty = new Zend_Validate_NotEmpty(); $notEmpty->setMessage('The field cannot be empty!');
$digits = new Zend_Validate_Digits(); $digits->setMessage('Please, enter only digits');
$password = new Zend_Form_Element_Password('password'); $passsword->setLabel('Password :') ->setRequired(true) ->addValidator($notEmpty, true) ->addValidator($digits, true)

use of regular expression validator.

->addValidator('regex', true,array('pattern'=>'/^[(0-9)]+$/', 'messages'=>array('regexNotMatch'=>'Please enter only digit.')) )


Here is list of some default validation classes in zend
You can also check in library/Zend/Validate for more details.

For more details mail me on nelson.desai@gmail.com or comments here.

--
Thank You
Nelson Desai

3 comments:

anjani02 said...

Very helpful and informative content. The simple explanation makes the subject easier to understand.microsoft azure devops training courses

online it guru said...

This was an interesting read. The information can be useful for both beginners and people who want to improve their existing knowledge.dell boomi training

OnlineITGuru said...

mulesoft online training provides flexible learning for understanding MuleSoft integration, API management, and application connectivity. Learners can build practical knowledge through online lessons and examples.

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by NDR Group | Bloggerized by Er. Nelson Desai | Love U My Friends