I have created a working form using both jquery and php validation.
I only know the bare minimum on PHP and have used a script from this guy - http://www.benjamink...php_validation/
Here is my php code:
<?php
$myemail = 'my@mail.com';//<-----Put Your email address here.
$title = 'Title';
$name = $_POST['name'];
$company = $_POST['company'];
$house = $_POST['house'];
$street = $_POST['street'];
$postcode = $_POST['postcode'];
$daynum = $_POST['daynum'];
$evenum = $_POST['evenum'];
$email = $_POST['email'];
$how = $_POST['how'];
$information = $_POST['information'];
foreach($_POST['product'] as $value) {
$product_msg .= " - $value";
}
$errors = array(); // set the errors array to empty, by default
$fields = array(); // stores the field values
$success_message = "";
if (isset($_POST['submit']))
{
// import the validation library
require("validation.php");
$rules = array(); // stores the validation rules
// standard form fields
$rules[] = "required,name,Name is required.";
$rules[] = "required,house,House number is required.";
$rules[] = "required,street,Street is required.";
$rules[] = "required,postcode,Post Code is required.";
$rules[] = "required,daynum,Daytime Number is required.";
$errors = validateFields($_POST, $rules);
// if there were errors, re-populate the form fields
if (!empty($errors))
{
$fields = $_POST;
}
// no errors! redirect the user to the thankyou page (or whatever)
else
{
// here you would either email the form contents to someone or store it in a database.
// To redirect to a "thankyou" page, you'd just do this:
// header("Location: thanks.php");
$to = $myemail;
$email_subject = "Quote: $name";
$email_body = "You have received a new quote from $name. ".
" Here are the details:\n \n Name: $name\n \n Company: $company\n \n House: $house\n \n Street: $street\n \n Postcode: $postcode\n \n Daytime Number: $daynum\n \n Evening Number: $evenum\n \n Email: $email\n \n Products: $product_msg\n \n Additional Information: $information\n \n How: $how";
$headers = "From: $title\n";
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: thank-you.html');
}
}
?>firstly i get the error - Warning: Invalid argument supplied for foreach()on line 16
I know it is referring to the code snippet for gathering the product checkbox values but I do not know why it is outputting this error.
If anyone could help me it would be greatly appreciated as it is the final bug before the project is finished.
Also any tips on general php contact form handler goodness would be great!
Thank you all!
Help

















