Hi,
I'm trying to get the errors using Zend_Filter_Input but I have a filling that its a little bit complex or I missed something simple
My code
PHP Code:
class object
{
//bla-bla-bla
public function update_data()
{
$this->_setFilter();
$this->_setValidator();
$options = array('escapeFilter' => array('StringTrim','HtmlEntities'));
$input = new Zend_Filter_Input($this->_filter, $this->_validator);
$input->setData($_POST);
$input->setOptions($options);
if($input->isValid()){
return true;
}
return false;
}
private function _setFilter()
{
$this->_filter = array (
'Location' => new NZTA_Filter_UppercaseWords(),
'CategoryID' => 'Digits',
'Title' => new NZTA_Filter_UppercaseWords(),
'WebsiteLink' => new NZTA_Filter_EmptyJustHttp(),
'ContactName' => new NZTA_Filter_UppercaseWords(),
'ContactEmail' => 'StringToLower',
);
}
private function _setValidator()
{
$this->_validator = array(
'Location' => array('NotEmpty', new Zend_Validate_StringLength(self::MINLENGTH,self::MAXLENGTH)),
'CategoryID' => array('Digits', new NZTA_Validate_InNoticeCategoryArray($this->categories)),
'Title' => array('NotEmpty', new Zend_Validate_StringLength(self::MINLENGTH,self::MAXLENGTH)),
'Description' => array('NotEmpty', new NZTA_Validate_UrlNotAllowed()),
'WebsiteLink' => new Zend_Validate_StringLength(0,self::MAXLENGTH),
'ContactName' => array('NotEmpty', new Zend_Validate_StringLength(self::MINLENGTH,self::MAXLENGTH)),
'ContactEmail' => array('NotEmpty', 'EmailAddress'),
);
}
}
I have an Error static class where I set the errors: Error::setError($errMessege) OR Error::setErrors(array), where array(errID=>errMsg)
To get the errors I use
PHP Code:
$errors = $input->getErrors();
Output
PHP Code:
Array
(
[Location] => Array
(
[0] => isEmpty
[1] => stringLengthTooShort
)
[Title] => Array
(
[0] => isEmpty
[1] => stringLengthTooShort
)
[Description] => Array
(
[0] => isEmpty
)
)
Nop, these are NOT errors. Ok, what else
PHP Code:
$message = $input->getMessages();
Output
PHP Code:
Array
(
[Location] => Array
(
[isEmpty] => Value is empty, but a non-empty value is required
[stringLengthTooShort] => '' is less than 5 characters long
)
[Title] => Array
(
[isEmpty] => Value is empty, but a non-empty value is required
[stringLengthTooShort] => '' is less than 5 characters long
)
[Description] => Array
(
[isEmpty] => Value is empty, but a non-empty value is required
)
)
Ok, looks like I got ones. I think this is a wrong error format output. How I can get them without coding loops, I want something simple.
Is it possible?