4

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 1

4
$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);
Sign up to request clarification or add additional context in comments.

3 Comments

Is there a way to validate set of form elements rather than one by one?
Got an example, have to try and see. akrabat.com/zend-framework/…
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()){...}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.