Re: QF validate

From: Date: Sat, 25 Feb 2006 00:31:22 +0000
Subject: Re: QF validate
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-23122@lists.php.net to get a copy of this message
On 2/24/06, Mark Steudel <mark@netriver.net> wrote: > Lets say you have the following form: > > $form = new HTML_QuickForm; > > $form->addElement('blah1') > $form->addRule('blah1'); > > $form->addElement('blah2') > $form->addRule('blah2'); > > if ( $form->validate() ) > { > process > } > else > { You could try adding this here: $form->setConstants(array('creditCard' => '')); This way the creditCard field is always empty when you display but when the form is submitted this line isn't called and the creditCard field is allowed to be changed. > $form->display(); > } > > When the user fails validation, the form is redisplayed with the values in > the fields, most of the time this is great. But is it possible to clear the > values for certain elements, say blah2? A real world example might be the > credit card information, lots of forms on validation errors just clear the > cc info and require the user to retype it in but still retain the shipping > and billing address. > Or you could unset() the fields in $_POST that you don't want to show up. However, this has to be done *before* the form is *created* (not displayed) due to how QF works and since you wouldn't know if the form is valid yet this isn't a good solution. I suggest the setConstants solution. -- Justin Patrin

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