Re: QuickForm2 form rules

From: Date: Sun, 11 Dec 2011 17:07:15 +0000
Subject: Re: QuickForm2 form rules
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-31351@lists.php.net to get a copy of this message
Hi Mark, On 06.12.2011 23:20, Mark Steudel wrote:
I'm creating a login form and want to make a database call and wanted to supply both username and the password and check those against whats in the database. Is there a way to access values of another element while in a callback method of a single element?
If you are using "callback" Rule, the callback will get the element's value, not the element itself. Thus, no.
Or should I try and subclass the quickform rule like you said?
Of course. Also please note that the Rule you add to a Container will currently need to set an error message on Container itself. In your case you'll probably want to do that on this fieldset:
Some code:
         $fieldset = $form->addElement( 'fieldset' )->setLabel( 'User Login' );
If you only set the errors on the contained elements, the form will probably be considered valid. Maybe we'll fix that behaviour, though.
On Tue, Dec 6, 2011 at 12:26 AM, Alexey Borzov<borz_off@cs.msu.su> wrote:
Hi Mark, On 06.12.2011 2:31, Mark Steudel wrote:
In the old QuickForm there were form rules. Is there a way to achieve the same thing in QuickForm2? I want to be able to compare two values from different form elements.
If you just wish to compare two form elements then you should probably use the built-in 'compare' Rule. There is an example for that in builtin-rules.php If you want to create something similar to old "form rule", you should subclass HTML_QuickForm2_Rule and implement validateOwner() and setOwnerError() methods in the child rule. There is no example for this currently, but it should be straightforward.


« previous php.pear.general (#31351) next »