QuickForm::validate() not processing custom rules when element is empty and not required (was Re: [PEAR-DEV] DB_DataObject_FormBuilder &
HTML_QuickForm questions with ArraySmarty renderer)

From: Date: Mon, 29 Aug 2005 07:48:10 +0000
Subject: QuickForm::validate() not processing custom rules when element is empty and not required (was Re: [PEAR-DEV] DB_DataObject_FormBuilder &
HTML_QuickForm questions with ArraySmarty renderer)
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-39594@lists.php.net to get a copy of this message
Hi, sorry I've only now discovered this has nothing to do with the FormBuilder itself and is a QuickForm issue. Still the question for this behaviour stands (see below). Markus Fischer wrote:
Your advice is to set an option to the FormBuilder to use a customized required message with requiredRuleMessage. Am I wrong that this applies to all required messages? Consider the current problem we're facing: We have a profile for the user to update. The user has two fields "password" and "verify password". If the user just wants update his profile, his password is NOT requred. But, if he wants to change his password, he MUST provide it two times. Again we're using custom callback handlers here. Problem: if the field "password" is filled out and the field "verify password" has NO value, the callback of "verify password" is not executed. Why are custom rules for fields not executed if the field is "not required" and empty?
In QuickForm::validate() the code reads: if ((!isset($submitValue) || $submitValue == '') && !$this->isElementRequired($target)) { // Element is not required continue 2; } I do not see the reason for this behaviour, why validation is not done on non-required fields and when the value is empty. I think I found the workaround with addFormRule, I haven't tested it yet. - Markus

« previous php.pear.dev (#39594) next »