Welcome Guest, Not a member yet? Register   Sign In
form_dropdown problem
#1

[eluser]GSV Sleeper Service[/eluser]
I've got a problem with form_dropdown. example below
Code:
// Start Date Arrays for drop down list
$start_month[] = "";
for ($i=1; $i<13; $i++) {
    $start_month[sprintf('d', $i)] = sprintf('d', $i);
}

form_dropdown('start_month',$start_month);
this generates the following
Code:
<select name="start_month">
<option value="0">
</option>
<option value="01">
01
</option>
...SNIP...
<option value="12">
12
</option>
</select>

where is the value of "0" coming from in the first option? I want a blank value here.
looking at form_helper.php I see this (I've added comments)
Code:
foreach ($options as $key => $val)
{
    $key = (string) $key; //a blank key gets converted to "0"
    $val = (string) $val; //yet a blank value does not, what gives?

    $sel = (in_array($key, $selected))?' selected="selected"':'';

    $form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
}
Is there a simple way to force a blank value?

Also - it would be nice if you make form_dropdown consistent with the rest of the form helpers i.e. being able to pass an array of attributes.
#2

[eluser]xwero[/eluser]
A blank key doesn't exist, every array value has a key. You just don't need to add it as a developer.

If you do this
Code:
$start_month[''] = "";
You should have an empty string value for the first option.
#3

[eluser]GSV Sleeper Service[/eluser]
you know, I did try that, but I was looking at the wrong form field to check the results. doh!
cheers xwero




Theme © iAndrew 2016 - Forum software by © MyBB