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 #2591

emptyOptionValue added to end of select list

Details

Submitted2004-10-22 16:41 UTC
Fromsmadeira at zoominternet dot net
StatusBogus
PackageHTML_QuickForm
PHP Version4.3.9
OSLinux 2.4.20-8
Roadmaps(Not assigned)

Comments

[2004-10-22 16:41 UTC] smadeira at zoominternet dot net

Description:
------------
I am using HTML_QuickForm to build a date element. I am using the addEmptyOption but it is putting the "empty Option" at the end of the select list. The following is the relevant code in date.php:

// Should we add an empty option to the top of the select?
if ($this->_options['addEmptyOption']) {
// Preserve the keys
$options = array($this->_options['emptyOptionValue'] => $this->_options['emptyOptionText']) + $options;
}

This is my hacked version of date.php that works and puts the empty option at the top of the select list.

// Should we add an empty option to the top of the select?
if ($this->_options['addEmptyOption']) {

$options2[$this->_options['emptyOptionValue']] = $this->_options['emptyOptionText'];
foreach($options as $key => $value){
$options2[$key] = $value;
}
$options = $options2;
}

SYSTEM DETAILS:

PEAR version - 1.3.1, QuickForm version - 3.2.4p11

PHP configure line : './configure' '--with-mysql=/usr/local/mysql' '--with-xml' '--with-curl=../../curl/curl-7.1' '--with-apache=../../apache/apache_1.3.31' '--with-openssl' '--with-zlib' '--enable-bcmath' '--enable-calendar' '--enable-dbx' '--enable-ftp' '--with-gd' '--with-mcrypt' '--with-mhash' '--enable-xslt' '--with-xslt-sablot=/usr/local/lib' '--with-expat-dir=/usr/local' '--with-iconv-dir=/usr/local' '--with-pear' '--with-jpeg-dir=/usr/lib' '--with-png-dir=/usr/lib'

Reproduce code:
---------------
<?php
require_once ('HTML/QuickForm.php');
$form = new HTML_QuickForm("testForm", 'POST');
$options = array('language' => 'en',
'format' => 'Y',
'addEmptyOption' => true,
'emptyOptionValue' => '',
'minYear' => 2004,
'maxYear' => 2010
);
$form->addElement('date', 'startdate', 'Start Date: ', $options);

$form->addElement('submit','submit','View Games');

echo'<html><head></head><body>';
$form->display();
echo '</body></html>';
?>

Expected result:
----------------
This is what I get with the hacked version (and what I think should be the proper result)......

<select name="startdate[Y]">
<option value=""> </option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
</select>

Actual result:
--------------
This is what I really get......

<select name="startdate[Y]">
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value=""> </option>
</select>