Re: QuickForm2 form rules

From: Date: Tue, 06 Dec 2011 19:20:10 +0000
Subject: Re: QuickForm2 form rules
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-31328@lists.php.net to get a copy of this message
Well, maybe I need to be more specific ... 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? Or should I try and subclass the quickform rule like you said? Some code: $form = new HTML_QuickForm2( 'login' ); $fieldset = $form->addElement( 'fieldset' )->setLabel( 'User Login' ); $username = $fieldset->addElement( 'text', 'username' )->setLabel( 'Username' ); $username->addRule( 'callback', 'Your username and or password is incorrect', array( &$this, 'authenticate' ) ); $password = $fieldset->addElement( 'password', 'password' )->setLabel( 'Password' ); $fieldset->addElement( 'submit', 'submitForm' )->setLabel( 'Submit' ); if ( $form->validate() && $this->authenticate( $_REQUEST['username'], $_REQUEST['password'] ) ) { echo 'Authenticated'; } return $form; // how would I get the password? function authenticate( $username ) { $sql = "SELECT username FROM users WHERE username = ? AND password = ?"; // return true or false if username and password combo found } Anyway thanks. MS 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. -- ----------------------------------------- Mark Steudel P: 425.298.7244 F: 206.260.3021 msteudel@gmail.com . : Work : . http://www.mindfulinteractive.com . : Play : . http://www.steudel.org/blog . : LinkedIn : . http://www.linkedin.com/in/steudel

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