I have a form with a multi-select inside. On submit I have this function:
$( "#addTrainForm" ).submit(function( event ) {
var dataString = $(this).serializeArray();
console.log(dataString);
event.preventDefault();
$.ajax({
type: "POST",
url: "/index.php/trainings/insertTraining",
data: dataString,
dataType: 'json',
success: function(data) {
$("div#addModal").hide();
location.reload();
}
});
return false;
});
Now where you can see that console log I get the following:
0: Object
name: "date"
value: "14/10/2013 16:22:46"
__proto__: Object
1: Object
name: "pool"
value: "1"
__proto__: Object
2: Object
name: "repeat_0"
value: "1"
__proto__: Object
3: Object
name: "distance_0"
value: "1"
__proto__: Object
4: Object
name: "style_0"
value: "1"
__proto__: Object
5: Object
name: "change_0"
value: "1"
__proto__: Object
6: Object
name: "time_0"
value: "1"
__proto__: Object
7: Object
name: "options_0"
value: "1"
__proto__: Object
8: Object
name: "options_0"
value: "2"
__proto__: Object
9: Object
name: "repeat_1"
value: "2"
__proto__: Object
10: Object
name: "distance_1"
value: "2"
__proto__: Object
11: Object
name: "style_1"
value: "1"
__proto__: Object
12: Object
name: "change_1"
value: "2"
__proto__: Object
13: Object
name: "time_1"
value: "2"
__proto__: Object
14: Object
name: "options_1"
value: "4"
__proto__: Object
15: Object
name: "options_1"
value: "5"
__proto__: Object
16: Object
name: "options_1"
value: "6"
Where you can see options_0 and options_1 have multiple values.
Now in the php function that get's called I read all the post data and write it straght to file:
public function insertTraining(){
$data=$this->input->post();
$this->baselib->logIt(print_R($data,true));
}
in there my options_0 and options_1 only have the last value available. I was expecting more of an array of values or a commaseperated string or something. This is what my log on the text file looks like:
Array
(
[date] => 14/10/2013 16:22:46
[pool] => 1
[repeat_0] => 1
[distance_0] => 1
[style_0] => 1
[change_0] => 1
[time_0] => 1
[options_0] => 2
[repeat_1] => 2
[distance_1] => 2
[style_1] => 1
[change_1] => 2
[time_1] => 2
[options_1] => 6
)
How can I get all the values for options_0 and options_1 to my php script? Is there some better way of using the functions I already am (like optional parameters?) or do i have to run a cycle arround all the values and find the options values and put them into an array and then send the to PHP with json?
Hope I managed to explain myself, Thank you, James