Okay I'll debug my form and post post the bug if / when I find it.

On the same form I can't get my custom validator to work. The validtation
is: if there is a start page, there needs to be an end page and vice versa.
Here is the validator:

class My_Validator_PageNo extends Zend_Validate_Abstract
{
    const NO_END = 'noEnd';
    const NO_START = 'noStart';

    protected $_messageTemplates = array(
        self::NO_END => 'A start page has been entered, you must specify an
end page',
                self::NO_START => 'An end page has been entered, you must 
specify a start
page'
    );

    public function isValid($value, $context = null)
    {
         
        $value = (string) $value;
        $this->_setValue($value);
       
            if (!empty($context['startPage'])
                         &&  empty($context['endPage']))
            {
                $this->_error(self::NO_END);
                                return false;
            }
         else if (! empty($context['endPage'])
              &&  empty($context['startPage']))
            {
                $this->_error(self::NO_START);
                                return false;
            }
    
          
        return true;
    }
}

I'm testing with '1' as the input value for startPage. While debugging I
found that $context was not set, not even an empty array. What an I missing?



Matthew Weier O'Phinney-3 wrote:
> 
> -- Waigani <[EMAIL PROTECTED]> wrote
> (on Tuesday, 02 September 2008, 12:00 AM -0700):
>> I'm validating a form. Most of the validation needs to be of the
>> following
>> format: IF there is content in a feild THEN that content needs to be
>> valid
>> xyz.
>> 
>> It seems that if I put any kind of validator on a feild, the form fails
>> if
>> their is no content in that field. How do I get around this?
>> 
>> Thank you for your time (and who ever is going to ZendCon see you soon!),
> 
> I'd like to see your code to see if it represents a reproduce case.
> 
> By default, elements are *not* required, meaning that if no value is
> submitted, no validators should be run. This has worked perfectly for me
> in every form I've written with Zend_Form -- perhaps others can chime in
> here, though, if they have experienced what you describe?
> 
> -- 
> Matthew Weier O'Phinney
> Software Architect       | [EMAIL PROTECTED]
> Zend Framework           | http://framework.zend.com/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Does-form-validator-implicitly-set-setRequired%28%29-to-true--tp19265120p19278502.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to