Forum Moderators: coopster
First of all I know nothing about php, I did a bit of programming with ADA and C++ over 4 years ago so my knowledge is very limited.
What am I trying to do is to have a contact form on my website. I got a free script from somewhere on the web, but am now trying to get it to do a few extra things.
What I want to happen is if all the fields that are entered in are validated OK then they are redirected to one webpage saying "I will reply asap", and if they mess something up then a message is displayed saying go back and correct the problem.
Before I started messing with the script it displayed the message about going back and correcting the problem OK but it didn't automatically redirect to the webpage saying "I will reply asap".
Here is the script befoe I broke it :)
<?php
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>
<!-- Reminder: Add the link for the 'next page' (at the bottom) -->
<!-- Reminder: Change 'YourEmail' to Your real email -->
<?php
if(!$visitormail == "" && (!strstr($visitormail,"@") ¦¦!strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
}
if(empty($visitor) ¦¦ empty($visitormail) ¦¦ empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}
$todayis = date("l, F j, Y, g:i a") ;
$attn = $attn ;
$subject = $attn;
$notes = stripcslashes($notes);
$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
";
$from = "From: $visitormail\r\n";
mail("info@example.com", $subject, $message, $from);
?>
</p>
</body>
</html>
and here is what I was attempting to do (stop laughing!)
<?php
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];
$sentok = $_POST['boolean'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>
<!-- Reminder: Add the link for the 'next page' (at the bottom) -->
<!-- Reminder: Change 'YourEmail' to Your real email -->
<?php
if(empty($visitor) ¦¦ empty($visitormail) ¦¦ empty($notes) ¦¦ empty($subject) ¦¦ empty($phone_number))
{
echo "<h2>Use Back - fill in all fields</h2>\n";
}
if(!$visitormail == "" && (!strstr($visitormail,"@") ¦¦!strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
}
$sentok = true;
$todayis = date("l, F j, Y, g:i a") ;
$attn = $attn ;
$subject = $subject;
$notes = stripcslashes($notes);
$message = " $todayis [GMT] \n
Message: $notes \n
From: $visitor ($visitormail)\n
Phone Number: $phone_number \n
";
$from = "From: $visitormail\r\n";
mail("info@example.com", $subject, $message, $from);
?>
<?php
<p>
if ($sentok == true)
<meta http-equiv="Refresh" content= "0;URL=http://www.example.com/thanks.htm">;
else
<meta http-equiv="Refresh" content= "0;URL=http://www.example.com/failed.htm">;
</p>
?>
</body>
</html>
Any ideas what I'm doing wrong or even what I'm on about?
Many thanks in advance,
Steve
<p>
if ($sentok == true)
<meta http-equiv="Refresh" content= "0;URL=http://www.example.com/thanks.htm">;
else
<meta http-equiv="Refresh" content= "0;URL=http://www.example.com/failed.htm">;
</p>
You've got that in a php block, which is ok for the if statement, but the html in there won't be output to the page unless you ECHO it out like this:
echo '<p>';
if ($sentok == true)
echo '<meta http-equiv="Refresh" content="0;URL=http://www.example.com/thanks.htm">';
All of your html content will need to be echoed in this way while you're inside of a <?php?> block. Don't forget to put it inside the single quotes.
Alternately you can do what I usually do, which is change the location header with php like this:
<?php
header('Location: http://www.example.com/thanks.htm');
?>
Hopefully one of those will work for you. Good luck. :)
-DR-
Echoing the Meta Refresh tags in the way I suggested is probably your best bet.
echo '<p>';
if ($sentok == true)
echo '<meta http-equiv="Refresh" content= "0;URL=http://www.example.com/thanks.htm">';
else
echo '<meta http-equiv="Refresh" content= "0;URL=http://www.example.com/failed.htm">';
echo '</p>';
[edited by: Duskrider at 2:32 pm (utc) on May 30, 2007]
Thanks for your help, I never would have got there without it.
If anyone is interested here is the script
<?php
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>
<!-- Reminder: Add the link for the 'next page' (at the bottom) -->
<!-- Reminder: Change 'YourEmail' to Your real email -->
<?php
if(empty($visitor) ¦¦ empty($visitormail) ¦¦ empty($notes) ¦¦ empty($subject) ¦¦ empty($phone_number) ¦¦ (!$visitormail == "" && (!strstr($visitormail,"@") ¦¦!strstr($visitormail,"."))))
{
echo '<meta http-equiv="Refresh" content= "0;URL=http://www.example.com/failed.htm">';
}
else
echo '<meta http-equiv="Refresh" content= "0;URL=http://www.example.com/thanks.htm">';
$todayis = date("l, F j, Y, g:i a") ;
$attn = $attn ;
$subject = $subject;
$notes = stripcslashes($notes);
$message = " $todayis [GMT] \n
Message: $notes \n
From: $visitor ($visitormail)\n
Phone Number: $phone_number \n
";
$from = "From: $visitormail\r\n";
mail("info@example.com", $subject, $message, $from);
?>
</body>
</html>
And Welcome to WebmasterWorld!
Good luck!