Re: Quickform Rules
| From: | Bertrand Mansion | Date: | Thu, 13 Jun 2002 11:24:34 +0000 |
| Subject: | Re: Quickform Rules | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-1649@lists.php.net to get a copy of this message | ||
le 13/06/02 6:58, Jeffery Cann à jeff@mridanga.com a écrit :
> 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
You'd better check your installation. This is not a bug and you don't need
to set anything to global. Check which version of HTML_Common you are using
and tell me if it works with the latest. Thanks,
Bertrand Mansion
Mamasam