Redirect to html after form is submitted

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
flumoxed
Forum Newbie
Posts: 2
Joined: Sun Apr 19, 2009 7:39 am

Redirect to html after form is submitted

Post by flumoxed »

Hi I hope someone out there can help me.

In an attempt to drag our companies web facilities into the 21st centuary i am starting to create many forms which when submitted email the details to a specified email adress etc. I have sucseeded to a point by following advice both from this site and following online tutorials.

Where i have a problem is that i want to redirect the customer to an html after they have submitted the form. I have acheived the redirection and a thankyou html appears which is great however i have a GIF and some links on this thankyou html, ie a link back to the home page once the customer has read my blurb but the gif and links do not work!!!

Is this because this just isn't possible or do i need to re-write my code. I am very new to PHP but my existing code is as follows............

<?php

/*subject and Email Variables */

$emailSubject = 'Campervan Van Form';
$webMaster = 'my@email';

/* Gathering Data Variables */

$titleField = $_POST['title'];
$nameField = $_POST['name'];
$addressField = $_POST['address'];
$telephoneField = $_POST['telephone'];
$emailField = $_POST['email'];
$campervanreg = $_POST['campervanreg'];
$arrivaldate = $_POST['arrivaldate'];
$noofnights = $_POST['noofnights'];
$noonboard = $_POST['noonboard'];
$total = $_POST['total'];
$comments = $_POST['comments'];


$body = <<<EOD
<br><hr><br>
Title: $title <br>
Name: $name <br>
Address: $address <br>
Telephone No: $telephone <br>
Email Address: $email <br>
Campervan registration: $campervanreg <br>
Arrival Date: $arrivaldate <br>
No of Nights: $noofnights <br>
No of People on Board: $noonboard <br>
Overall Cost: $total <br>
Comments: $comments <br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

/* Results rendered as HTML */

$theResults = <<<EOD
<html>

THIS IS WHERE I JUST COPY AND PASTE MY HTML CODE WHICH CONTAINS THE GIF AND LINK

</html>

EOD;
echo "$theResults";


is there a much simpler way of redirecting someone to an html of my choice once they have submitted the form or is there something i am doing wrong which makes the GIF not appear or the link work??

I dont need the PHP to validate my form as this is done via spy validation widgets before the form in submitted as i wish to keep it all as simple as possible.

Any help with re-writing the above would be much appreciated and im sure it is very simple but its beaten me.

Many thanks in advance
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: Redirect to html after form is submitted

Post by jazz090 »

the problem is not in ur php code, is your html output that prevents the links and the gif working, are u using header() to redirect or are you simple using require() or include() to embed html?
flumoxed
Forum Newbie
Posts: 2
Joined: Sun Apr 19, 2009 7:39 am

Re: Redirect to html after form is submitted

Post by flumoxed »

Hi, many thanks,

So the problem is not with my php, this should be working fine but its to do with the html.

Unfortunatley you have lost me with ...... header() to redirect or are you simple using require() or include() to embed html? .... as i am not amazingly gifted with code as use dreamweaver. My html code for the thankyou page is as follows..........

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #FFF;
margin-left: 100px;
}
#z {
font-size: 12px;
}
#z {
font-size: 36px;
}
.z {
color: #003;
}
#z {
color: #003;
}
.z {
font-size: 24px;
}
body table {
font-size: 18px;
}
body table {
font-size: 16px;
}
body table {
font-size: 10px;
}
#c {
font-size: 18px;
}
#c {
font-size: 24px;
}
#c {
font-size: 24px;
}
-->
</style></head>

<body>
<table width="922" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td align="left"><img src="PHP/camper.gif" width="945" height="378" /></td>
</tr>
<tr>
<td align="center"><span class="z" id="z">Thankyou for filling out the Campervan Booking Form</span></td>
</tr>
<tr>
<td align="center"><span class="z" id="z">Your Form has been submitted successfully</span></td>
</tr>
<tr>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center"><span class="z" id="c">WPNSA will contact you shortly by either the email address or telephone number given to confirm the booking and arrange payment</span></td>
</tr>
<tr>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center"><span class="z" id="c">We look forward to seeing you soon !!!</span></td>
</tr>
<tr>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td width="922" align="center" id="c">Please do not click the back button, to return to the site please click <a href="index.htm">here</a></td>
</tr>
</table>
</body>
</html>

Does this help at all? or do you need more information reagrding the header require or include?.
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: Redirect to html after form is submitted

Post by jazz090 »

no i meant do you load the file uve given me (above) directly into the php code or do u use header() to chnage the url and redirect or do u use require(ur.html) or include(ur.html) to load the above data, regardless of what ive wrote, imagine the absoloute route of ur web directory if ur runnning on localhost then the absolute route would be: http://localhost/ or http://127.0.0.1/. then you have ur camper.gif which is located in a folder called PHP. i strogly recomend that you find the reletivity of PHP to localhost so if you have htdocs/PHP/camper.gif then the absooute path would be http://localhost/php/camber.php in which u can refrence it by the relative path: "/PHP/camper.php" in you html. note the "/" at the begining of the path.
xplore
Forum Newbie
Posts: 16
Joined: Mon Apr 06, 2009 12:06 pm

Re: Redirect to html after form is submitted

Post by xplore »

Because you wish to redirect the user after they submit the information (in your case even if they hit submit button with no input) to your thank you page. Using the function header("Location: 'insert relative path here'") you can take the user to another page automatically. Now you want your code to do this only after the user has submitted the information so I suggest putting this code at the top of your document BEFORE any white space in the document.

<?php

// if one var is set they all are
if (isset($_POST['title'])) {
// user has submitted
header("Location: thanks.php");
}
else {
echo "<h1>Welcome to the 'form name' form</h1>";
}


?>
Post Reply