Pergunta

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.

Foi útil?

Solução

$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);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top