Welcome Guest, Not a member yet? Register   Sign In
form_dropdown return value not key
#1

[eluser]jordantkj[/eluser]
Hi,
I've created 3 dynamically populated form_dropdowns, they are getting populated correctly with the expected values. However, when I access them from my search_model, the values are keys and not the actual values. For instance, the first value in the dropdown is posting "0", the second "1", and so on. My form_input and checkboxes are returning the expected values.

My questions...
Does anyone know if the dropdown is supposed to return the key only? If so, is there anyway to get it to return the text value it displays in the dropdown?

Here is what the array returns, top 3 are from dropdowns. They keys are correct, but I don't want the keys...

Array
(
[item] => 2
[model_num] => 0
[part_num] => 0
[is_loaner] => no
[is_active] => no
[search_term] => wtf
)

Thanks!
#2

[eluser]boltsabre[/eluser]
Best to make an array of values for each drop down and use it to populate your drop downs, then in your model you can simply use some native PHP
Code:
$key = $this->input->post('item');
if(isset($my_dropdown_array[$key])){
   $value = $my_dropdown_array[$key];
}

That's it in it's basic novice form, personally I'd create a validation callback function to check that the dropdown post value (which is actually your array key) does actually exist in the array - good practice and makes your application safer against hacking. Then you can call your model from your controller and just do this:
Code:
$value = $my_dropdown_array[$this->input->post('item')];
#3

[eluser]jordantkj[/eluser]
Ok, should have thought to use the array passed to the view. It would be nice if the documentation would contain this type of information.

Thanks for the help!

-Tyler
#4

[eluser]Aken[/eluser]
What you're experiencing is standard functionality. Read the Form helper page, and you'll see how the array is turned into HTML. If you set up your array of values for each form_dropdown() properly, you will get the expected values in your POST data.




Theme © iAndrew 2016 - Forum software by © MyBB