Welcome Guest, Not a member yet? Register   Sign In
Reading multi select input
#1

[eluser]Unknown[/eluser]
Ok guys, probably a simple question. I want a multi-select:

<select name="roles" multiple>
<option value='1'>admin</option>
<option value='2'>user</option>
</select>

I want the value of this multi-select in my program. Say I select both roles. When I do:

$this->input->post("roles")

I only get the value 2, not an array or something. What am I doing wrong? Thanks!
#2

[eluser]Unknown[/eluser]
Solved! You need to use [] on the select name, like so:

<select name=“roles[]” multiple>
<option value=‘1’>admin</option>
<option value=‘2’>user</option>
</select>

I don't know why this isn't in the documentation somewhere. I took a stab since this is the way struts 2 does it.




Theme © iAndrew 2016 - Forum software by © MyBB