Is there a way to validate and filter pure HTML forms with Zend Validation and Zend Filter classes ? Please give some example if you have, I couldn't find out any.
1 Answer
$email = $this->_getParam('email');// form's $_POST or $_GET
$email_validator = new Zend_Validate_EmailAddress();
if(!$email_validator->isValid($email)){
// Error, throw(Exception)
}
To see what validation you can use, open your library folder and go to library/Zend/Validate/ path, you will see many files/classes. That are available classes for validation like Alnum.php, Alpha.php, Barcode.php, CreditCard.php, etc. Just create instance and call method isValid();
new Zend_Validate_FileName();
The same thing is for filters, on path library/Zend/Filter/ you can see a lot of classes. Almost all of them implement an interface Zend_Filter_Interface(Interface.php) where you can find one method:
public function filter($value);
-
Is there a way to validate set of form elements rather than one by one?– ShaolinCommented Jan 21, 2013 at 11:16
-
Got an example, have to try and see. akrabat.com/zend-framework/…– ShaolinCommented Jan 21, 2013 at 11:17
-
On that example you can see eg. $validators = array('body'=>'Alpha'); where key is $_POST['body'] and validation is Alpha.php. Apply that logic to everything else... and call only once if($input->isValid()){...} Commented Jan 21, 2013 at 11:28