Hi there, OK first of all, big apologies for what I assume is really fundamental errors in the structure of my code. I'm really new at this and still learning, but I'm almost at the stage of giving up on this one. I've rewritten the code so many times I can't even remember what it was originally like (when it incidentally worked better).
What I am trying to do, is pass a simple form over to a php email script on an external server which validates the form, sends the email (if valid) and returns the user to a success/fail/error page on the original host server.
I'm sure looking at the code might enlighten some of you more to what I'm trying to do, no doubt it may just confuse the hell out of most. (I know I am at this point!)
Anyway here it is:
<?php
if(isset($_POST['email'])) {
//grab referal info from POST
$path = explode('/', $_SERVER['HTTP_REFERER']);
$referer = $path[2];
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "jr@creativeheat.co.uk";
$email_subject = "Website booking inquiry";
$errortype = "";
function died($error) {
// your error code can go here
header( 'Location: http://'.$referer.'/booking/'$error ) ;
echo $error."<br /><br />";
echo "We are very sorry, but there were error(s) found with the form your submitted. ";
echo "These errors appear below.<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
//Start by setting the values of the checkboxes
if (isset($_POST['booking_0'])) { $book1 = $_POST['booking_0']; if( $book1 == 'Bedroom(s)') { $book1 = " The Bedroom(s) n"; }}
if (isset($_POST['booking_1'])) { $book2 = $_POST['booking_1']; if( $book2 == 'Meeting Room') { $book2 = " The Meeting Room n";}}
if (isset($_POST['booking_2'])) { $book3 = $_POST['booking_2']; if( $book3 == 'Barn') { $book3 = " The Barn n"; }}
if (isset($_POST['booking_3'])) { $book4 = $_POST['booking_3']; if( $book4 == 'Campsite') { $book4 = " The Campsite n";}}
//then check for an all false
$errortype = "";
$error_message = "";
if (!isset($_POST[booking_0]) && !isset($_POST[booking_1]) && !isset($_POST[booking_2]) && !isset($_POST[booking_3])) {
//redirect to NO BOOKING TYPE SELECTED page
$error_message = 'error';
$errortype = 'bookingerr';
died($errortype) ;
}
//check everything else
$errortype = "";
$error_message = "";
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['number']) ||
!isset($_POST['email']) ||
!isset($_POST['adults']) ||
!isset($_POST['children']) ||
!isset($_POST['from_date']) ||
!isset($_POST['to_date']) ||
!isset($_POST['disabled']) ||
!isset($_POST['parking']) ||
!isset($_POST['general'])) {
//redirect to GENERAL INVALIDATION page
$error_message = 'error';
$errortype = 'requirederror' ;
// died($errortype) ;
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$telephone = $_POST['number']; // required
$email_from = $_POST['email']; // required
$adults = $_POST['adults']; // required
$children = $_POST['children']; // required
$fdate = $_POST['from_date']; // required
$tdate = $_POST['to_date']; // required
$disabled = $_POST['disabled']; // not required
$parking = $_POST['parking']; // not required
$comments = $_POST['general']; // not required
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}$";
$errortype = "";
$error_message = "";
if(!eregi($email_exp,$email_from)) {
//redirect to INVALID EMAIL page
$error_message = 'error';
$errortype = 'emailinvalid';
// died($errortype) ;
}
$string_exp = "^[a-z .'-]+$";
$errortype = "";
$error_message = "";
if(!eregi($string_exp,$first_name)) {
//redirect to INVALID FIRSTNAME page
$error_message = 'error';
$errortype = 'fnameerror' ;
// died($errortype) ;
}
$errortype = "";
$error_message = "";
if(!eregi($string_exp,$last_name)) {
//redirect to INVALID LASTNAME page
$error_message = 'error';
$errortype = 'lnameerror' ;
// died($errortype) ;
}
$errortype = "";
$error_message = "";
if(strlen($comments) < 2) {
//redirect to INVALID COMMENTS page
$error_message = 'error';
$errortype = 'commentserror' ;
// died($errortype) ;
}
$string_exp = "^[0-9 .-]+$";
$errortype = "";
$error_message = "";
if(!eregi($string_exp,$telephone)) {
//redirect to INVALID TELEPHONE page
$error_message = 'error';
$errortype = 'telephoneerror' ;
// died($errortype) ;
}
if(strlen($error_message) > 0) {
died($errortype) ;
}
$email_message = "Form details below.nn";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($first_name)." ".clean_string($last_name)."n";
$email_message .= "Contact number: ".clean_string($telephone)."n";
$email_message .= "Email address: ".clean_string($email_from)."nn";
$email_message .= "Interested in availability of the following: n";
$email_message .= $book1.$book2.$book3.$book4."n";
$email_message .= "Date from: ".clean_string($fdate)."n";
$email_message .= "Date to: ".clean_string($tdate)."nn";
$email_message .= "Number of...n";
$email_message .= "Adults: ".clean_string($adults)."n";
$email_message .= "Children: ".clean_string($children)."nn";
$email_message .= "Disabled? ".clean_string($disabled)."n";
$email_message .= "Parking? ".clean_string($parking)."nn";
$email_message .= "Additional Information: nn";
$email_message .= clean_string($comments);
// create email headers
$headers = 'From: '.$email_from."rn".
'Reply-To: '.$email_from."rn" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
//redirect to SUCCESS page
header( 'Location: http://'.$referer.'/booking/success' ) ;
}
?>
The form is here: http://claverhamtrust.squarespace.com/booking/ I have set values for most of the fields to avoid having to retype information every time I submitted the form. The email aspect of this for works perfectly, it is just the error processing and redirect that is broken/poorly written.
Absolutely ANY help on this would be much appreciated. I'm going to continue to try in the mean time though, so if things don't seem to function as you'd expect given the code above it may be because I am changing it live. If I make any progress though, I'll post it here.
Thanks
Working with popups and such in a class
I've recently started building my applications completely enclosed in classes. I like the fact that I can base everything off one root and work with that, but I'm having a problem with popups
Simple Variable Question
Hi everyone.... again,I am really getting into php still. Learning more every day. I love it.But I have run into a problem I cannot solve.From what I understand, you can only "echo
Performance impact of cookies
Hi, I was just wondering what impact there would be in terms of performance if you where to set then increment the value of a cookie on each page of a site. Also, being a server side script; how
All possible combinations of Strings from table in PL/SQL
Hi,
cURL and Sessions
Ohai.So, I'm trying to cURL a bunch of things off of a page, and put them into a session. I've added all of the items so they look like $_SESSION['fur'] = ge_item(6814)Now I just need to figure out
my code does not work.
I have a code problem.Quote"<a href=index.php?gogo=ureticidetay&'?l={$letter}'>{$ letter}</a>" this is not working. but need link like this
Searching keywords from array
Hello everyone, Im just wondering if someone could help me with another issue im having. Im still learning PHP and I have been for a few months now, but every now and then I get stuck on small things.
Looking for help reading a .txt or .ini file and outputting the info.
I have a file called Info.ini and It has the following info:Code: [General]Online=0I would like it to be in a php file as just 0 if possible. Also how would I do this from php file to php file and let
word wrap in emails help needed
Hello, I understand how wordwrap works in php and have used it well before. However when I used wordwrap on a variable that is going to be emailed it puts the line breaks in well before it should.
How to use Substr
I want to check for the word CATEGORY: inside a string which can be CATEGORY: ITEMand remove the word CATEGORY: leaving only ITEM inside the string....In case the string does not have CATEGORY: before