Re: HTML_Quickform Bug on setDefaults and/or setValue with text fields
| From: | Justin Patrin | Date: | Sun, 11 Jul 2004 18:32:47 +0000 |
| Subject: | Re: HTML_Quickform Bug on setDefaults and/or setValue with text fields | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13639@lists.php.net to get a copy of this message | ||
What browser are you using to test this? Have you checked the HTML
source to make sure that the value is still the wrong one? Mozilla
keeps the values from the form and sometimes overrides what is sent by
the server.
On Sun, 11 Jul 2004 23:10:42 +1000, Del <del@babel.com.au> wrote:
>
> Hi,
>
> I'm having a problem with what I believe is a bug in HTML_QuickForm (3.2.3).
>
> After processing a submit for a form, if I then reset any of the text fields
> to default values using setDefaults and/or setValue, the displayed version of
> the fields don't change (e.g. what I see when I do toHtml). If I do a print_r
> of the Quickform element object, however, I see that the value has been
> changed.
>
> I think the problem is that the _html var in the class Renderer/Default.php
> doesn't get touched, and hence toHtml outputs the old, pre-setValue HTML.
>
> Here is some code that exercises that bug.
>
> Can anyone help identify a fix for this? I've been bashing my head against
> it for a while but I can't see where in the QuickForm tree of objects it's
> broken.
>
> --
>
> <?php
>
> //
> // This script exercises a bug in HTML_QuickForm. The bug is that resetting
> // a text field using setDefaults or setting its value using setValue has no
> // effect on the HTML output for the field when toHtml is called, even though
> // the internals of the form element show that the value has been set. Doing
> // this on a different type of field (eg: a date field) appears to work fine.
> //
>
> require_once("HTML/QuickForm.php");
>
> $form = new HTML_QuickForm('some_form');
>
> $form->addElement('header', '', 'A Bug');
> $form->addElement('text', 'atextfield', 'A Text Field',
> array('size'=>'30'));
> $form->addElement('date', 'some_date', 'A Date',
> array('format'=>'d-F-Y', 'minYear'=>1999,
> 'maxYear'=>(date('Y')+4)));
>
> //
> // create the array with the default values for the form here
> //
> $defaults = array('atextfield' => '12341234',
> 'some_date' => array(
> 'Y' => date('Y'),
> 'F' => date('n'),
> 'd' => date('j')));
>
> $buttons[] = &HTML_QuickForm::createElement('submit', null, 'Save
> Changes');
> $buttons[] = &HTML_QuickForm::createElement('reset', null, 'Reset');
> $form->addGroup($buttons);
>
> if ($form->validate()) {
> //
> // Set default values for form
> //
> $form->setDefaults($defaults);
> //
> // Reset some values to defaults. BUG: This doesn't work -- the form keeps its values
> from
> // the last submit, even though a print_r of the element reveals that it has been set
> // to null.
> //
> $element = $form->getElement('atextfield');
> $element->setValue('12341234');
>
> print "<pre>\n";
> print_r($element);
> print "</pre>\n";
>
> //
> // Resetting the value with a date field, however, works fine.
> //
> $element = $form->getElement('some_date');
> $element->setValue(array(
> 'Y' => date('Y'),
> 'F' => date('n'),
> 'd' => date('j')));
>
> } else {
> // form didn't validate.
>
> //
> // Set default values for form
> //
> $form->setDefaults($defaults);
> }
>
> // render the form.
> $body = $form->toHtml();
>
> ?>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <html>
>
> <head>
> <title></title>
> <meta name="GENERATOR" content="Quanta Plus">
> </head>
> <body>
>
> <?php print $body; ?>
>
> </body>
> </html>
>
> --
> Del
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> !DSPAM:40f13a50110252502313716!
>
>
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--