Welcome Guest, Not a member yet? Register   Sign In
How to get the text value from form dropdown
#1

[eluser]Unknown[/eluser]
Hello,

I am brand spankin' new to PHP/CI and I am struggling to get the value from a dropdown box in a form. I can get a numeric value but I need the text value so that I can save it to my database which expects a text enum.

I pass this array to my view
$data['location_enums'] = array('UK', 'US', 'Brazil', 'India', 'China');

In my view I display the dropdown box with...
<p>
<label for="location">Location:</label>
&lt;?php echo form_dropdown('location', $location_enums, 'UK'); ?&gt;
</p>

My controller calls add_user() in my model if the entire form passes validation. The add_user() method is as follows...

public function add_user($location, $role)
{

$data=array (
'name'=>$this->input->post('username'),
'password'=> md5($this->input->post('password')),
'location'=> $this->input->post('location'),
'role'=> $this->input->post('role'),
'email'=>$this->input->post('email')
);
$this->db->insert('Users',$data);

From what I can gather $this->input->post('location') returns a numeric value and not the text value that the user has selected but it's the text value I need. Any ideas?

Thank you.


Messages In This Thread
How to get the text value from form dropdown - by El Forum - 04-21-2012, 06:55 AM
How to get the text value from form dropdown - by El Forum - 04-21-2012, 09:14 AM
How to get the text value from form dropdown - by El Forum - 04-23-2012, 04:00 AM
How to get the text value from form dropdown - by El Forum - 04-23-2012, 04:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB