PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_QuickForm » Bug #5251

setDefaults() does not work on select box after form POST

Details

Submitted2005-08-31 06:43 UTC
Fromagrubb at unimelb dot edu dot au
Assignedavb
StatusClosed
PackageHTML_QuickForm
PHP Version4.3.10
OSdebian linux
Roadmaps(Not assigned)

Comments

[2005-08-31 06:43 UTC] agrubb at unimelb dot edu dot au

Description:
------------
This problem affects multi-stage forms, ie. where you click submit (or 'next') from one form and post some values to the next form. However some default data may come from a database or other source. This type of default data on the second level form is not populated properly. Text areas and text inputs do work properly, but selects do not. (I haven't tested other elements).

I have noticed this problem on two separate machines while migrating some code which worked properly on an older set up.

The problem occurs on one machine with these PEAR libraries:

HTML_Common 1.2.1 stable
HTML_QuickForm 3.2.5 stable
HTML_Table 1.5 stable
PEAR 1.3.2 stable

thanks for your help, I hope this is a bug not my mistake.

Test script:
---------------
$selectListArray = array(
'1' => '1',
'2' => '2',
'3' => '3');

$defaults['select1'] = '2';
$defaults['select2'] = '2';

$editForm = new HTML_QuickForm('editForm','POST',$_SERVER['SCRIPT_NAME']);

if(!empty($_POST)) $editForm->addElement('select', 'select2','Select 2: ', $selectListArray);
else {
$editForm->addElement('select', 'select1','Select 1: ', $selectListArray);
$editForm->addElement('submit','submit','Submit Form');
}
$editForm->setDefaults($defaults);
$editForm->display();

Expected result:
----------------
you should see '2' selected in both the first and second select boxes.

Actual result:
--------------
you see '2' in the first text box, but when you click submit you see '1' in the second text box.

[2005-08-31 23:55 UTC] agrubb at unimelb dot edu dot au

avb, thanks for prompt response. a good tip too, but this code was only intended for 'single' select.

[2005-09-12 06:20 UTC] f dot dot dot fischer at at at zeiss dot dot dot de

Here is a workaround that is working for me.
First transfer the post-variables you need in to "normal" variables, ex.
$username = $_POST['username'];
Second unset($_POST);
Afterwards a new quickform with setDefaults() can be build.

[2005-09-19 16:48 UTC] bugs dot pear at gage dot fr

I think that the method to determine _flagSubmitted should seriously be reviewed.

[2005-09-20 14:15 UTC] guy dot heatley at gmail dot com

HTML_Quickform version 3.2.5
I'm finding that $myForm->setDefaults() simply isn't working for select input types. i.e the specified defaults are never selected.

Can someone please give an example of using setValue() to directly set these elements.

Thanks!

[2005-09-20 14:38 UTC] guy dot heatley at gmail dot com

I figured it out. Here's what I got, just to save you a few minutes!
:-)
[My select element is called "leader_id"]

$form->setDefaults($the_defaults);
$myElement =& $form->getElement('leader_id');
$myElement->setValue($module_details['leader_id']);
$the_page->addContent($form->toHtml().$form_notes );

Cheers!

[2005-10-24 19:59 UTC] xdecow at gmail dot com

see setConstants()