Have input form like <input type="text" name="record_date[] ...
Part of ajax that sends form to other php file is
var values = $("form").serialize();
$.ajax({
type: 'POST',
data: { 'Values' : values },
dataType: 'json',
The other php file receives data
$values = $_POST['Values'];
As understand this parse_str($_POST['Values'],$output);
creates array ($output
is array)
But with this print_r(json_encode($output));
I see nothing (expected to see array with values etc.)
If use echo json_encode($output['record_date']);
then all works and get entered values.
Trying to create array and then to use the array like this
foreach ($output as $i=>$output_value ) {
echo json_encode($output_value[$i]);
}
Changed to this echo json_encode($output_value['record_date'][$i]);
but in both case echo nothing.
As I understand main question is how to "modify/convert" parse_str($_POST['Values'],$output);
to php array
$_POST['Values']
looks like this: record_date%5B%5D=02.07.2013&record_date%5B%5D=01.07.2013
Possibly instead of parse_str
need to use something else
Update
If in ajax use dataType: 'json',
and in php
foreach ($output as $key => $output_value) {
echo json_encode($output_value);
}
then get nothing.
If commentdataType: 'json',
, then see ["02.07.2013","01.07.2013"].
If instead of echo json_encode($output_value);
use echo $output_value;
then see long list of ArrayArrayArrayArrayArray
.
If inside foreach
use var_dump($output_value);
then see like this
array(2) { [0]=> string(1) "2" [1]=> string(1) "6" }
...............
array(2) { [0]=> string(10) "02.07.2013" [1]=> string(10) "01.07.2013" }
Seems echo $output[$key][0]
inside foreach does what is necessary...
Finally made conclusion that must use such kind of code
foreach ($output[record_date] as $key => $output_value) {
echo $output_value. ' output value<br>';
echo $output[other_name_from_html_input][$key]. ' output date selector value<br>';
}