Contact Form Message on contact form not in new window?

I’ve followed a tutorial and created a contact form. Once the form has been submitted the browser opens a new page displaying a success message. How do I display the message at the bottom of the contact form itself?

[php]<?php
if(isset($_POST[‘email’])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = “Express Travel Booking”;

$Name = $_POST[‘Name’]; // required
$email_from = $_POST[‘email’]; // required
$Telephone = $_POST[‘Telephone’]; // not required
$PickUp = $_POST[‘PickUp’]; // required
$DropOff = $_POST[‘DropOff’]; // required
$Passengers = $_POST[‘Passengers’]; // required
$Date = $_POST[‘Date’]; // required
$Time = $_POST[‘Time’]; // required
$Comments = $_POST[‘Comments’]; // required

$email_message = “Form details below.\n\n”;

function clean_string($string) {
$bad = array(“content-type”,“bcc:”,“to:”,“cc:”,“href”);
return str_replace($bad,"",$string);
}

$email_message .= “Name : “.clean_string($Name).”\n”;
$email_message .= “email address : “.clean_string($email_from).”\n”;
$email_message .= “Telephone : “.clean_string($Telephone).”\n”;
$email_message .= “Pick Up : “.clean_string($PickUp).”\n”;
$email_message .= “Drop Off : “.clean_string($DropOff).”\n”;
$email_message .= “Passengers : “.clean_string($Passengers).”\n”;
$email_message .= “Date : “.clean_string($Date).”\n”;
$email_message .= “Time : “.clean_string($Time).”\n\n”;
$email_message .= “Comments : \n\n”.clean_string($Comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>

Thank you for your enquiry. We will be in touch soon.

<?php } ?>[/php]

[code]

Contact Form
Name email address Telephone Pick Up Drop Off Passengers Date Time Comments
[/code]

move everything to one page change the action

<form method="post" action="sendmail.php">

change to

<form method="post" action="">

That didn’t work. While the message now displays on the form, the form does not send any data and I get validation errors. The page validated previously.

Forgot to change the extention to php. I get the data but the message displays at the top of the page. I’ve tried to position it with css.

did you try putting the form above the php ?

No and I would prefer to keep the php and html in seperate pages.

Must have read your explanation wrong thinking you wanted it on one page.
You are sending them to another page with your action, so how can you go back to the same page ?

What would be the point in opening a blank page ?

Maybe explain what you want better.

If its just a responce after you post the message without knowing if the page was sent or not at the bottom of the page, this will not tell you person filling out the form is this form has really been sent.

You need to validate the form entries and not send them to another page.
or send them and sent them back with a responce (maybe use header(‘location, form.php?responce=true’)
or form.php?responce=false ).

then get the responce true or false with
$_GET[‘responce’].

with the $GET respoonce print error or sent message.

Your clean string function what is is cleaning ???

It does not clean anything from the string passed to it, I would look for a better form example with proper validation and captcha.

Sponsor our Newsletter | Privacy Policy | Terms of Service