This is the meal planner app I'm still working on. I've gotten a lot of useful help so far. You can see the view source at http://maureenmoore.com/momp_tests/122212.html
I am using the following in my process.php (which the jquery form gets submitted to)
$stack = array();
foreach ($_REQUEST as $key => $value)
{
array_push($stack,$value);
}
$stack = array_values($stack);
print_r($stack);
$comma_separated = implode(",", $stack);
echo "
" . $comma_separated . "
";
When I click the submit button at localhost it shows an error for array to string conversion because it's a multidimensional array. How can I get rid of the first null key without resorting to a recursive function? I don't see the error any more now that I've uploaded it to my hosting account but it's not printing a comma-separated list because it's a multidimensional array with a key of null.
Sorry I got confused, let me know if i have understood it, right. You are getting an error because it is a multidimensional array.
Try this
foreach ($_REQUEST as $tempArray) {
foreach ($tempArray as $key => $value) {
array_push($stack,$value);
}
}
or
$tempArray = $_REQUEST;
foreach ($tempArray[0] as $key => $value) {
array_push($stack,$value);
}
You can use array_filter() to remove nulls
$new_array_without_nulls = array_filter($array_with_nulls, 'strlen');
And array_reduce() to convert to comma separated instead of implode http://php.net/manual/en/function.array-reduce.php
The data that you are sending to your php script is {data: selectedBoxes}
and you are using the post method. And selectBoxes
is an array containing the stuff that is dragged to the right-hand box.
To get your data in php, you just need to iterate over the data
post variable:
foreach ($_POST['data'] as $key => $value)
{
// get all meals that were dragged
}
Also note, if you drag one of the things in the box around, you get multiple versions of the same meal.