PDA

View Full Version : Submission form - error message


tommisauce
08-30-2007, 01:59 PM
Hi folks,

I have adapted a submission form based on a previously created working version. The original version only had Name, email address and comments section. The adapted version is for a Limo hire service which has many more inputted areas. I have adapted the code for the file however, even when all the boxes are filled the error message appears (the error message should only appear if all the boxes aren't filled). I'm not sure why it's not working but if you could cast your eyes over the file - I would be very grateful.

Here's the link:
http://www.vipink.co.uk/LimoService/LimoBooking.php

and here's the PHP coding:


<?php
if(isset($_POST['Submit'])) {
// begin by assuming that there is nothing suspicious
$suspect = false;

// pattern to check for suspicious content
$pattern = '/Content-type:|Bcc:|Cc:/i';

// function to check for suspect phrases
function isSuspect($val, $pattern, &$suspect) {
// if the variable is an array, loop through each element
// and pass it recursively back to the same function
if (is_array($val)) {
foreach ($val as $item) {
isSuspect($item, $pattern, $suspect);
}
}
else {
// if one of the suspect phrases is found, set Boolean to true
if (preg_match($pattern, $val)) {
$suspect = true;
}
}
}

// check the $_POST array
isSuspect($_POST, $pattern, $suspect);

// check email address for illegal characters
// this is moved up from its position in the original script
$email = $_POST['email'];
if (eregi("\r",$email) || eregi("\n",$email)){
$suspect = true;
}

// if nothing suspicious has been found, process the form
if (!$suspect) {
$name = $_POST['name'];
$comments = $_POST['comments'];
$mailing = $_POST['mailing'];
if($name == '' or $vipnumber == '' or $address == '' or $email == '' or $tel == '' or $pickupdate == '' or $pickaddress == '' or $dropaddress == '' or $picktime == '' or $droptime == '' or $numberofguests == '' or $places == '') {
$err = true;
$msg = 'Please complete the whole form before submission.';
}
else {
$mailmsg = 'The following email has been sent from the contact form:' . "\n\n";
$mailmsg.= 'Name: ' . $name . "\n";
$mailmsg.= 'vipnumber: ' . $vipnumber . "\n";
$mailmsg.= 'address: ' . $address . "\n";
$mailmsg.= 'email: ' . $email . "\n";
$mailmsg.= 'tel: ' . $tel . "\n";
$mailmsg.= 'pickupdate: ' . $pickupdate . "\n";
$mailmsg.= 'pickaddress: ' . $pickaddress . "\n";
$mailmsg.= 'dropaddress: ' . $dropaddress . "\n";
$mailmsg.= 'picktime: ' . $picktime . "\n";
$mailmsg.= 'droptime: ' . $droptime . "\n";
$mailmsg.= 'numberofguests: ' . $numberofguests . "\n";
$mailmsg.= 'places: ' . $places . "\n";
$mailmsg.= 'numberofhours: ' . $numberofhours . "\n";
if($mailing == 'true') {
$mailmsg.= 'How many hours for VIPink limo hire';
}
// send the mail

/********************************** New section *********/
// prepare additional headers
$headers = "From: $email\r\n";
$headers .= "Reply-to: $email";
/************************************************** ******/

// send the mail - CHANGE THE LAST ARGUMENT TO $headers
if(mail('thomas@dt7design.co.uk','Contact Form', $mailmsg, $headers)) {


// although this will work, you should use a full URL to redirect the page
// for example: header('Location: http://www.example.com/thankyou.html');
header("Location: thankyou.html");
}
}
}
// suspicious content has been found - send a neutral message
else {
$err = true;
$msg = 'Sorry, your message could not be sent';
}
}
?>

davidj
08-30-2007, 02:43 PM
you have this...

if($name == '' or $vipnumber == '' or $address == '' or $email == '' or $tel == '' or $pickupdate == '' or $pickaddress == '' or $dropaddress == '' or $picktime == '' or $droptime == '' or $numberofguests == '' or $places == '') {
$err = true;
this will always equal true as you dont have any $_POSTS set for the additional information

you are passing the $_POST array which is catching all the form contents but you are not setting the key in $_POST for the additional info you added


$name = $_POST['name'];
$comments = $_POST['comments'];
$mailing = $_POST['mailing'];