views:

21

answers:

1

This works...

form_dropdown('location', $location_options, $this->input->post('location'));

But when I try and use an array to add extra attributes, it stops working... Why is this?

$attributes = array(
    'name' => 'location',
    'id' => 'location'
);

form_dropdown($attributes, $location_options, $this->input->post('location'));

The name of the dropdown list is included in the array of attributes so i don't see how this is any different to the first example. Whenever the form is posted posted back, it resets to the start.

Can anyone help me out with this? Thanks

A: 

It's just the wrong syntax.

Please have a look at the docu: http://codeigniter.com/user_guide/helpers/form_helper.html

form_dropdown('location', $location_options, $this->input->post('location'), "id='location'");

Your code should look something like the above. And by the way: if you're using the form_validation library you could use set_value instead of $this->input->post ...

mseo
Ok, looks like wrong syntax... Doesn't explain how you can pass in an array of attributes and still keep the values on a "form_input" field but cant do the same with a "form_dropdown" field without losing the post data.
Quigley
You add your attributes as a string as the last argument of form_dropdown().
mseo