Page 1 of 1

Problem with validate empty textbox

Posted: Wed Apr 09, 2008 5:22 am
by rsg
At first sorry because my english is very poor.

I have:
....
$number1 = new Zend_Form_Element_Text('number1');
$number1->addValidator('CheckNumbers')

$number2 = new Zend_Form_Element_Text('number2');
$number1->addValidator('CheckNumbers')
....

and i write my costum validation for them:

<?php
class My_Validate_CheckNumbers extends Zend_Validate_Abstract
{
const NOT_MATCH = 'notMatch';

protected $_messageTemplates = array
(
self::NOT_MATCH => 'NAPAKA: Vnesite pravilne vrednosti'
);

public function isValid($value, $context = null)
{
$value = (string) $value;
$this->_setValue($value);

if (is_array($context))
{
if( (empty($context['number1']) && empty($context['number2'])) )
{
$this->_error(self::NOT_MATCH);
return false;
}

}
return true;
}
}
?>
And i have problem because this is return true, when i put something in textboxes(correct),
but also when is empty return true - not error

i try if( (($context['number1']=="") && ($context['number2'])="") ) - also this one doesn't work

but every thing is working OK.
examples:
if(is_numeric($context['number1'] || ....) working OK
if(($context['number1']="something_to_compare" || ....) working OK
...
but i can't check empty fields, where is the problem?