Welcome Guest, Not a member yet? Register   Sign In
Dropdown troubles
#1

[eluser]timj[/eluser]
Here's my code:

Code:
function future_select()
{
        $options=array();
        for($i=1; $i<=$52; $i++){
        $options[$i]=date("Y-m-d", strtotime('+'.$i.' Wednesday'));
        }
        return form_dropdown('run_date',$options);
}

This generates a dropdown list of every Wednesday for the next 52 weeks. Works. Only problem is the select options is the first portion of the array, the number. I'd like the select option to be the second portion, the actual date for insertion into the database. I can't see a lot of flexibility for the helper in the User Guide.

Can someone yield some assistance?
#2

[eluser]theprodigy[/eluser]
The form_dropdown array is an assoc array. The keys of the array are the option values, the values of the array are what get shown. If you want the date to be what gets sent, you need to make the keys of the array = the date you want inserted.

Code:
function future_select()
{
        $options=array();
        for($i=1; $i<=$52; $i++){
            $date = date("Y-m-d", strtotime('+'.$i.' Wednesday'));
        $options[$date]=$date;
        }
        return form_dropdown('run_date',$options);
}
Something like that should work.
#3

[eluser]timj[/eluser]
That worked. Thanks for the explanation.




Theme © iAndrew 2016 - Forum software by © MyBB