Reputation: 1632
I'm using the chosen UI library to select multiple values for a post param named 'tables'. In the Chrome network console I can check that is working how I expected:
Form data
checkin:2012-06-15 16:00:00
checkout:2012-06-15 17:00:00
tables:14
tables:15
tables:16
customer:28
But when I try to recover this tables info in the controller
var_dump($this->input->post('tables'));
I only got the last value for the param:
string(2) "16"
I also try var_dump($_POST['tables']);
when the same result.
Upvotes: 1
Views: 2120
Reputation: 146219
Just an example of how to pass an array to server from html form
HTML
<form>
<input name="tables[]" value="value1" />
<input name="tables[]" value="value2" />
....
</form>
PHP (codeigniter)
$tables_array=$this->input->post('tables'); // an array with all values of tables[] input/item of form
if you print_r($tables_array);
then the output will be
Array ( [0] => value1 [1] => value2 )
Upvotes: 3
Reputation: 364
I don't have any experience with CodeIgniter, but the basic solution you're looking for is either to make an array and pass that (if CodeIgniter has a function for passing an array in POST that would be best, otherwise make a function that appends the values and delimits them with a comma or semicolon and another function to interpret that on the other end) or to pass, say "tables1:14", "tables2:15", "tables3:16" and then process them once you receive them. I think the array would probably be the best way, personally, but you may have a reason to use the second method.
Upvotes: 0