Suppose I have a field for IP address. It has 2 validators
– Ip
– Db_NoRecordsExists
$ip = new Zend_Form_Element_Text('ip');
$ip->setLabel('IP')
->setRequired(true)
->addValidator('Ip')
->addValidator('Db_NoRecordExists', false, array('table' => 'blacklist_ips', 'field' => 'ip'));
In DB ip stored as integer, so I have a problem with validation on unique, using Db_NoRecordsExists.
Is it possible to pass ip as converted to integer, but only for one of validator (because in case of converting field value before validate, Ip validator will gives error), something like this (added new parameter “value”):
$ip->setLabel('IP')
->setRequired(true)
->addValidator('Ip')
->addValidator('Db_NoRecordExists', false, array('table' => 'blacklist_ips', 'field' => 'ip', 'value' => Custom_Convert_Ip::ip2long([value_of_ip])));
Thanks in advance.
One way would be to write your own validator
Zend_Validate_Db_NoRecordExists. For example:I haven’t tested it, but it I think it should do the trick.
Hope it helps.