How to use the Zend validator:
There are two ways to use Zend Validator. You can build a validator chain and display all the errors to the user once, or you can validate each user inputs one by one.
in /lib/Zend/Validate folder, you can find lots of different types of input validation tools. For detail documentation and examples please see: http://framework.zend.com/manual/en/zend.validate.set.html
To use the tool in our appion processing(example):
include_once("../lib/Zend/Validation/NotEmpty.php);
$validatorEmpty = new Zend_Validate_NotEmpty();
if (!$validatorEmpty->isValid($value)) createTomoAlignerForm("<b>ERROR:</b> message");
To use the tool in other places (example):
include_once("../lib/Zend/Validation/NotEmpty.php);
$validatorEmpty = new Zend_Validate_NotEmpty();
if (!$validatorEmpty->isValid($value)) echo "print error message.";
If you don't want to have so many include_once statement, you can use as follow:
foreach (glob("../lib/Zend/Validate/*.php") as $filename) {
include_once($filename);
}
To validate an integer >= 1 (example)
$validatorEmpty = new Zend_Validate_NotEmpty();
if (!$validatorEmpty->isValid($value)) createTomoAlignerForm("<b>ERROR:</b> Input value can not be empty");
$validator = new Zend_Validate_Int();
if(!$validator->isValid($value)) createTomoAlignerForm("<b>ERROR:</b> Value must be integer.");
$validator = new Zend_Validate_GreaterThan(array('min'=>0));
if(!$validator->isValid($value)) createTomoAlignerForm("<b>ERROR:</b> Value must >= 1");
From the example you can see, if you need to reuse certain validation tool, you can create an unique instance name ($validatorEmpty), otherwise, you can use re-use the instance name when you create new validation instance.
Let me know if you have any question.
Thanks.
Eric