Re: Quickform Rules

From: Date: Thu, 13 Jun 2002 04:58:11 +0000
Subject: Re: Quickform Rules
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-1638@lists.php.net to get a copy of this message
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Birgir Stefansson wrote: > 2) When I submit the form and there is an error in the input all the > fields are reset to blank. How do I keep fields that are valid so a user > doesn't have to input all fields again ? Here's a workaround for what seems to be a bug -- painful for large forms with many fields: 1. Reference your field name in the php global array. 2. Use the 'setValue' function for the element and give it the field variable referenced from the global array. The first time through the variable is empty, so your field will also be empty. After a submit error, the field value exists and is populated into your form field. Here's an incomplete snippet -- field variable 'assigningCompany'. Line 1 declares $assigningCompany to be global scope. Lines 8-9 created a text element with the HTML form field named 'assigningCompany'. Finally, line 10 sets the default value. Make sure that your element object name does not match the HTML variable name or else you'll get the word 'Object' for a blank field! 1 global $name; 2 3 $form = new HTML_QuickForm( $PHP_SELF, 'POST' ); 4 $form->addHeader( 'Company Information'); 5 6 // Company information 7 8 $element = &HTML_QuickForm::createElement('text', 9 'name' 'Company Name ',''); 10 $element->setValue($name); 11 $element->setSize(40); 12 $element->setMaxLength(40); 13 $form->addElement( $element ); Later, Jeffery & Quenten - -- Enable Your Information Age (c) http://mridanga.com/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAj0IJmcACgkQt0J81Q+7BCDxGACfUyngFBLsBpEjTo22mnVTOMk3 EA0AoKABrIHUGyksiBQFG252O//0/n5Q =u4TD -----END PGP SIGNATURE-----

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