Welcome to my Blog

I am Nelson Desai. I complete computer engineering.

This is my personal blog. Here I share some post, which can helpful for me, my friends and you.

Some post may be illegal to share like some crack and keys. but, i think.. which things put online then it's not be secure any more whatever company try.

So, I requested you pls download and use it at your risk. and don't upload it again online.

Thank You for peeping my blog.. Have a Good Day!

Showing posts with label zend validattors. Show all posts
Showing posts with label zend validattors. Show all posts

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

Twitter Delicious Facebook Digg Stumbleupon Favorites More

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