Hello,
I am pretty new to php. I know how to do normal input fields and radio buttons, but not checkboxes. I can get it to pass one of the values from the checkboxes, but once i select more than one it does not work.
Here is snippets of the code I have.
The actual form (request.php )
<form method="POST" action="cforms/mark_p.php">
...
<br>Check all that apply:
<input type="checkbox" name="checkboxone[]" value="completeset">
<input type="checkbox" name="checkboxone[]" value="companyintro">
<input type="checkbox" name="checkboxone[]" value="commprintbrochure">
<input type="checkbox" name="checkboxone[]" value="commprintflyer">
<input type="checkbox" name="checkboxone[]" value="digprintbrochure">
<input type="checkbox" name="checkboxone[]" value="concealbrochure">
<input type="checkbox" name="checkboxone[]" value="largeformat">
<input type="checkbox" name="checkboxone[]" value="portablebanner">
<input type="checkbox" name="checkboxone[]" value="directmailflyer">
<input type="checkbox" name="checkboxone[]" value="directimageflyer">
...
<br><input type="submit" name="submit" value="Submit">
</form>
mark_p.php
<?php
while (list ($key,$val) = @each ($checkboxone)) {
echo "$val,";
}
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "test@test.com";
$Subject = "testsite.com - Request Marketing Pack";
$checkboxone = Trim(stripslashes($_POST['checkboxone']));
...
?>
Thanks ahead of time for any help!
nevermind found a work around!
foreach($_POST['formmanufac'] as $value) {
$formmanufac_msg .= "Checked: $value\
";
}
//body of email
$Body .= "Forms Manufacturing: ";
$Body .= "\
";
$Body .= $formmanufac_msg;
$Body .= "\
";
Thanks Siric. I seem to still be having a problem with the checkboxes.
Should that code be going into the request.php or mark_p.php? Keep in mind I want this value to pass through into the email.
I put it in mark_p.php and its still not working.
<?php
$formmanufac = $_POST['formmanufac']; // <------ You forgot this line
while (list ($key,$val) = @each ($formmanufac)) {
echo "val - $val<br/>";
}
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "drew@test.com";
$Subject = "test.com - Sample Request";
$Name = Trim(stripslashes($_POST['Name']));
$Company = Trim(stripslashes($_POST['Company']));
$Street = Trim(stripslashes($_POST['Street']));
$Street2 = Trim(stripslashes($_POST['Street2']));
$City = Trim(stripslashes($_POST['City']));
$State = Trim(stripslashes($_POST['State']));
$Zip = Trim(stripslashes($_POST['Zip']));
$Phone = Trim(stripslashes($_POST['Phone']));
$Website = Trim(stripslashes($_POST['Website']));
$formmanufac = Trim(stripslashes($_POST['formmanufac']));
$commprint = Trim(stripslashes($_POST['commprint']));
$digitaloffset = Trim(stripslashes($_POST['digitaloffset']));
$largeformat = Trim(stripslashes($_POST['largeformat']));
$otherprinted = Trim(stripslashes($_POST['otherprinted']));
$howdidyouhear = Trim(stripslashes($_POST['howdidyouhear']));
$otherhear = Trim(stripslashes($_POST['otherhear']));
$mailinglist = Trim(stripslashes($_POST['mailinglist']));
// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\\"refresh\\" content=\\"0;URL=error.php\\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\
";
$Body .= "Company: ";
$Body .= $Company;
$Body .= "\
";
$Body .= "Street: ";
$Body .= $Street;
$Body .= "\
";
$Body .= "Street2: ";
$Body .= $Street2;
$Body .= "\
";
$Body .= "City: ";
$Body .= $City;
$Body .= "\
";
$Body .= "State: ";
$Body .= $State;
$Body .= "\
";
$Body .= "Zip: ";
$Body .= $Zip;
$Body .= "\
";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\
";
$Body .= "Website: ";
$Body .= $Website;
$Body .= "\
";
$Body .= "formmanufac: ";
$Body .= $formmanufac;
$Body .= "\
";
$Body .= "commprint: ";
$Body .= $commprint;
$Body .= "\
";
$Body .= "digitaloffset: ";
$Body .= $digitaloffset;
$Body .= "\
";
$Body .= "largeformat: ";
$Body .= $largeformat;
$Body .= "\
";
$Body .= "otherprinted: ";
$Body .= $otherprinted;
$Body .= "\
";
$Body .= "howdidyouhear: ";
$Body .= $howdidyouhear;
$Body .= "\
";
$Body .= "otherhear: ";
$Body .= $otherhear;
$Body .= "\
";
$Body .= "mailinglist: ";
$Body .= $mailinglist;
$Body .= "\
";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){
print "<meta http-equiv=\\"refresh\\" content=\\"0;URL=thanks.php\\">";
}
else{
print "<meta http-equiv=\\"refresh\\" content=\\"0;URL=error.php\\">";
}
?>
The body field for formmanufac shows up in the email like thie:
formmanufac: Array
siric
May 10, 2010, 9:07pm
4
You forgot to read the POSTed variable
<?
$checkboxone = $_POST['checkboxone']; // <------ You forgot this line
while (list ($key,$val) = @each ($checkboxone)) {
echo "val - $val<br/>";
}
......
?>