CodeIgniter Forums
form_dropdown() with set_select() - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: form_dropdown() with set_select() (/thread-2016.html)

form_dropdown() with set_select() - El Forum - 07-11-2007

I read this topic regarding using form_dropdown() with set_select(), but it doesn't seem to be working for me.

I am doing a simple Month-DD-YYYY dropdown combination to accept a person's age.

//set month array
//set days array
for ($i=1;$i<=31;$i++)

//set years array            

for ($i=2007;$i>=1940;$i--){

so, setting dropdowns:
<p>Enter your date of Birth:</p>
<div style="float:left">Month:<br>&lt;?=form_dropdown('month',$months)?&gt;</div>
<div style="float:left">Day:<br>&lt;?=form_dropdown('day',$days)?&gt;</div>
<div style="float:left">Year:<br>&lt;?=form_dropdown('year',$years)?&gt;</div>

now for the validation set_select(), from the docs in the User's Guide, I must have access to the <OPTION> tags. I don't see how to get to those while using the form helper functions. It seems to me that I must choose one or the other.

Certainly there's a way to smoothly use these in conjunction?

form_dropdown() with set_select() - El Forum - 07-16-2007

The best thing I found for this was simply to use the validation data like any other input.

&lt;?= form_dropdown('field_id', $field_values, $this->validation->field_id); ?&gt;

form_dropdown() with set_select() - El Forum - 07-16-2007

Thanks beyondwords. This was a simple solution, I guess I was making it harder than it was!

form_dropdown() with set_select() - El Forum - 07-17-2007

Thats all well and good, but what if you wish to default to a certain option before the form is submitted?


Ignore me im dumb and lazy, i was thinking it would auto do it when instead we should of course do it like so

form_dropdown('dropDown', $array,($this->input->post('formElement') ? $this->input->post('formElement') : $defaultValue))

form_dropdown() with set_select() - El Forum - 08-06-2010

Phunky thanks