Zend makes us perform our own sanitation of data because the requirements change so much from field to field.
You are apparently not using Zend_Form to build you form or you would use the standard filters and validators included with Zend_Form
.
You do have access to the same validators and filters Zend_Form uses when not using Zend_form.
These are available when you use Zend_Filter_Input
.
Zend_Filter_Input is designed specifically to filter and validate information contained in an assiciated array like the ones supplied buy a $_GET
or a $_POST
array.
Basic usage is all in the controller/action:
$filters = array(
//month is the array key, Digits is the name of the filter class
'month' => 'Digits',
//account is the array key, Digits is the name of the filter class
'account' => 'StringTrim'
);
$validators = array(
//account is the array key, Digits is the name of the validator class
'account' => 'Alpha',
//* is a valid wildcard for validators and filters
'*' => 'NotEmpty'
);
$data = $this->getRequest()->getPost();
//everything in the constructor
$input = new Zend_Filter_Input($filters, $validators, $data);
//or
$input = new Zend_Filter_Input($filters, $validators);
$input->setData($data);
There is a lot more that can be done with filters and validators, check out Zend_Filter_Input for more info.