Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie for redirection question

Status
Not open for further replies.

Benluke

Technical User
Apr 2, 2004
112
GB
Hi,

Im changing all my forms to php for more sucurity and am fairly new to php. I have the following script which i want to tweek a little. Instead of a message coming up when the form has been succesfully submitted i want to redirect to a thankyou page. I cant work out how to do this. Can anybody help

Thanks

Ben

<?


if($_POST['Submit']){
// This is only called when the form is submitted.

// Get the Variables From the Form

$name = $_POST['name'];
$email = $_POST['email'];
$reason = $_POST['reason'];
$besttime = $_POST['time'] . ' ' . $_POST['nightorday'] ;
$message = $_POST['message'];


// Set the variables to send an email to the Owner and Sender (this message will be send with HTML, to send this
// Email using Text, All you have to do write the message like this:
// $message = ' Thank you for sending and email'; ect...

// This is the Subject of this message
$subj= "Christmas Gift Voucher";
// Headers will included The From, Return Email
$header = "Return-Path: benerskine@noble-manhattan.com\r\n";
$header .= "From: Noble Manhattan Coaching Ltd <#@#.com>\r\n";
// Header also include the Type, and Language the Email being sent, E.g. for Arabic Typed Email
// You will use iso-1256
$header .= "Content-Type: text/html; charset=iso-8859-1;\n\n\r\n";

//Message for the Owner
$ownermes = '<p><b>W&P </b></p>
<p align="justify"><b>The Contact Person\'s Name Is:<font color="blue"> ' . $name . ' </font></b></p>
<p align="justify"><b>Their E-Mail is: <a href=mailto:' . $email . '>' . $email . '</a> </b></p>
<p align="justify"><b>Their Telephone Number is:<font color="blue"> ' . $phone . '</font> </b></p>
<p align="justify"><b>Their Best time to contact:<font color="blue"> ' . $besttime . ' </font></b></p>
<p align="justify"><b>Their Reason Of Contact is:<font color="blue"> ' . $reason . '</font> </b></p>
<p align="justify"><b>The Message they wrote was:<font color="blue"> ' . $message . '</font> </b></p>
<p><b>Thank You For Using Sample Site As Your Personal Design</b></p>
<p><b>Sample Site Inc. Website Manager,</b></p>
';
//Message for the sender
$sednermess = '<p><b>Thank You, ' . $name .' For contacting W&P Assessment and Training Centre</b></p>
<p align="justify"><b>We have recieved your message. Someone will return Your Message
As soon as possible, Thank you for your interest. </b></p>
<p><b>W&P Assessment and Training Centre</b></p>
';
// This is the email of the owner
$to = '#@.co.uk';

//This will actually send the emails
// Send one to the owner
mail ($to,"$subj",$ownermes,$header);
// Send one to the sender (thank you message)
mail ($email,"$subj",$sednermess,$header);

// This message will show on the board for the customer to OK everything

// Explode the name, so we only show the first name
$newname = explode(' ',$name );

$message = 'Your Email Has Been Sent, Thank You: ' . $newname[0] . '.';
}
// End of Send mail, Show Form, With Either The Message, or New
?>
<html>
<head>
<title>Contact Us :: Sample Company</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<form action="<? echo $_SERVER['PHP_SELF'];?>" method="post" name="contactus" id="contactus" onSubmit="return validateme(this)">
<table width="500" align="center" cellpadding="5" cellspacing="5">

<?

// This is the message you that will show ONLY when the form is completely submitted and the email was sent!
if($message != NULL) { ?>
<tr>
<td colspan="2"><div align="center"><strong><font color="#FF0000" face="Verdana, Arial, Helvetica, sans-serif"><? echo $message;?></font></strong></div></td>
</tr>
<tr>
<? } ?>
<td colspan="2"><div align="center"><font face="Georgia, Times New Roman, Times, serif"><strong>Contact
Us:</strong></font></div></td>
</tr>
<tr>
<td width="227"><font face="Georgia, Times New Roman, Times, serif"><strong>Your
Name:</strong><font color="#FF0000">*</font></font></td>
<td width="236"><font face="Georgia, Times New Roman, Times, serif">&nbsp;
<input name="name" type="text" id="name" size="30" style="font-weight:bold;">
</font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Your E-mail:</strong><font color="#FF0000">*</font></font></td>
<td><font face="Georgia, Times New Roman, Times, serif">&nbsp;
<input name="email" type="text" id="email" size="30" style="font-weight:bold;">
</font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Your Reason
of Contact:</strong><font color="#FF0000">*</font></font></td>
<td><font face="Georgia, Times New Roman, Times, serif">&nbsp;
<select name="reason" id="reason" style="width:115px;font-weight:bold;">
<option value="Billing">Billing</option>
<option value="Comments">Comments</option>
<option value="Complaints">Complaints</option>
<option>Sales</option>
<option value="Support" selected>Support</option>
</select>
</font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Best Time
To Call:</strong></font></td>
<td><font face="Georgia, Times New Roman, Times, serif">&nbsp; <strong><font face="Georgia, Times New Roman, Times, serif">
<select name="time" id="time" style="width:115px;font-weight:bold;">
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="1:00">1:00</option>
<option value="1:30">1:30</option>
<option value="2:00">2:00</option>
<option value="2:30" selected>2:30</option>
<option value="3:00">3:00</option>
<option value="3:30">3:30</option>
<option value="4:00">4:00</option>
<option value="4:30">4:30</option>
<option value="5:00">5:00</option>
<option value="5:30">5:30</option>
</select>
<input type="radio" name="nightorday" value="am" class="buton">
<font size="2">AM
<input name="nightorday" type="radio" value="pm" checked class="buton">
PM</font></font></strong> </font></td>
</tr>
<tr>
<td><font face="Georgia, Times New Roman, Times, serif"><strong>Your Message:</strong><font color="#FF0000">*</font></font></td>
<td><font face="Georgia, Times New Roman, Times, serif">&nbsp;
<textarea name="message" id="message" style="width:215px;font-weight:bold;height:50px;"></textarea>
</font><font face="Georgia, Times New Roman, Times, serif">&nbsp; </font></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Send Contact Request" style="background-color:#CC0099;font-weight:bold;color:white;">
</div></td>
</tr>
</table>
</form>
</body>
</html>


<script>


// check the form
function validateme(thisform){
var isvalid = true;

if(thisform.name.value.length <3){
// invalid Message
alert("Please Enter A Valid Name, At Least 3 Characters Minimum!");
isvalid = false
thisform.name.focus();
}

if(isvalid){
if (thisform.email.value.indexOf("@")==-1 || thisform.email.value.indexOf(".")==-1 || thisform.email.value.indexOf(" ")!=-1 || thisform.email.value.length<6){
// invalid Message
alert("Please Enter A Valid Email!");
isvalid = false
thisform.email.focus();
}
}

if(isvalid){
if(thisform.message.value.length <3){
// invalid Message
alert("Please Enter A Valid Message, At Least 3 Characters Minimum!");
isvalid = false
thisform.message.focus();
}
}

return isvalid;
}

</script>
 
Code:
header("HTTP/1.1 301 Moved Permanently"); 
header("location: [URL unfurl="true"]http://domain.tld/path/to/message.php");[/URL] 
header("Connection: close");

the connection: close is needed for IE.
301 moved, is for website crawlers not f*** up your website ranking!

if it's in a page not submitted to, there is no problem, but why not always optimize?

Olav Alexander Mjelde
Admin & Webmaster
 
right ok im lost,

please bare with me i have little php experience

DaButcher; where would i put the code you supplied?

This is where i am with this,

I can get the script to work pefectly but i want the user to be redirected to a thankyou page when they have submitted the form. At the moment this is whats happening

// This message will show on the board for the customer to OK everything

// Explode the name, so we only show the first name
$newname = explode(' ',$name );

$message = 'Your Email Has Been Sent, Thank You: ' . $newname[0] . '.';
}

which appears on the page the form is on

Thanks really appreciate the help

Ben
 
put it below your mail functions, so it redirects AFTER the mail is sent.

If you wish to keep the browser-input variables, you have to do something to keep them.. eg. redirect with querystring, save in session, or something in that way.

ps. I would make PHP validate input, rather than something client-side, like javascript.

but, focus on what you HAVE to do first, then take the rest when you have the time to do it.

Good luck!

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top