I’ve made a form, wich gets the info for the checkboxes in it from a xml file. Now I want to mail that form with php, but I got an “Warning: Invalid argument supplied for foreach() in mailer.php on line 8” error. Here’s the checkbox part off my form, written in javascript:
if (window.XMLHttpRequest)
{// IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","dehoek.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
x=xmlDoc.getElementsByTagName("product");
for (var i=0;i<x.length;i++)
{
document.write('<input name="check[]" id="checkbox'+i+'" type="checkbox" value="'+(x[i].getElementsByTagName("naam")[0].childNodes[0].nodeValue)+'" /><label for="checkbox'+i+'">'+(x[i].getElementsByTagName("naam")[0].childNodes[0].nodeValue)+' €'+(x[i].getElementsByTagName("prijs")[0].childNodes[0].nodeValue)+' </label>');
}
And here’s my php:
$aan = $_POST['to'];
$onderwerp = "Bestelling";
$naam = $_POST['naam'];
$email = $_POST['email'];
$message = "Producten:";
foreach($_POST['check'] as $value) {
$check_msg .= "$value\n";
}
$body = "From: $naam\n E-Mail: $email\n Message:\n $message\n $check_msg";
echo "Uw bestelling is succesvol verstuurd.";
mail($aan, $onderwerp, $body);
I hope someone of you know what’s wrong with my code, because I really don’t get it.
Thanks in advance,
Jan Thiemen
You are currently, in your PHP script, trying to read from
$_POST:But your page is requesting using the HTTP GET method :
So, there is no such thing as
$_POST['check']— as$_POSTonly contains data when a page is requested using HTTP POST, and not GET.If you request your page using and HTTP GET, you must, in your PHP script, read from
$_GET, and not$_POST.