Hi All,
(EDIT: Amazingly, I clicked on another thread to give myself a break from coding and i found half the answer immediately. Thanks Pritaeaus http://www.daniweb.com/forums/post1478160.html#post1478160. However, when validation is not passed I still get the messed up page so if anyone can help, I'd be most grateful.)
(EDIT 2: I am certain that this is linked to the die() function used within the died() function)
I have a HTML and PHP form that is not displaying properly when I submit it. It was working (I could receive emails through it) but when the validation failed I only got a messed up page. Now I've messed it up further (don't know how) and it no longed sends mail and the page is still messed up whether it passes validation or not. Can anyone help me?
<!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 name="XAR Files" content="index_htm_files/xr_files.txt"/>
<title>Steadfast Design - Contact Us</title>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"/>
<meta name="Generator" content="Xara HTML filter v.3.1.0.319"/>
<meta name="keywords" content="steadfast design,steadfastdesign,steadfast web design,web design,web site,website,web sites,websites,web designer, website designer, web site designer,webpage, web page, webpage, contact, contact us"/>
<meta name="description" content="Steadfast Design - Contact Us"/>
<link rel="stylesheet" type="text/css" href="index_htm_files/xr_main.css"/>
<link rel="stylesheet" type="text/css" href="index_htm_files/xr_text.css"/>
<script type="text/javascript" src="index_htm_files/roe.js"></script>
</head>
<body style="background-color: #282D33">
<div class="xr_ap" id="xr_xr" style="width: 800px; height: 600px; top:0px; left:50%; margin-left: -400px;">
<script type="text/javascript">var xr_xr=document.getElementById("xr_xr")</script>
<!--[if IE]><div class="xr_ap" id="xr_xri" style="width: 800px; height: 600px; clip: rect(0px 800px 600px 0px);"><![endif]-->
<!--[if !IE]>--><div class="xr_ap" id="xr_xri" style="width: 800px; height: 600px; clip: rect(0px, 800px, 600px, 0px);"><!--<![endif]-->
<img class="xr_ap" src="index_htm_files/0.png" alt="" title="" style="left: 240px; top: 215px; width: 545px; height: 348px;"/>
<img class="xr_ap" src="index_htm_files/1.png" alt="" title="" style="left: 240px; top: 211px; width: 1px; height: 348px;"/>
<img class="xr_ap" src="index_htm_files/107.png" alt="" id="Repeating:58MonotoneFooter" title="" style="left: 15px; top: 553px; width: 770px; height: 43px;"/>
<span class="xr_s0" style="position: absolute; left:15px; top:325px;">
<span class="xr_tl" style="top: -11px;"><span class="xr_s1">Services</span></span>
<span class="xr_tl" style="top: 4px;">Steadfast Design is pleased to offer </span>
<span class="xr_tl" style="top: 20px;">high quality web design services to our </span>
<span class="xr_tl" style="top: 35px;">clients</span>
</span>
<img class="xr_ap" src="index_htm_files/108.png" alt="" title="" style="left: 15px; top: 305px; width: 191px; height: 1px;"/>
<span class="xr_s2" style="position: absolute; left:262px; top:246px;">
<span class="xr_tl" style="top: -14px;">Steadfast Design - Contact Us</span>
<span class="xr_tl xr_s4">
<?php
if(isset($_POST['email'])) {
$email_to = "EMAIL ADDRESS REMOVED";
$email_subject = "You have received a message from the contact page of SITE NAME REMOVED";
function died($error) {
echo "There is an error(s). Click the Return button and rectify the error(s) before continuing.<br />";
echo "The error(s) appears below.<br /><br />";
echo $error."<br /><br />";
?>
<input type="image" src="index_htm_files/144.png" name="image" width="94" height="23" onClick="history.go(-1)">
<?php
die();
}
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['message'])) {
died();
}
if(isset($_POST['confirm_email'])) {
exit();
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$message = $_POST['message']; // required
$error_message = "";
$email_validate = "/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i";
if(!preg_match($email_validate,$email_from)) {
$error_message .= 'The email address is invalid.<br /><br />';
}
$string_validate = "/^[a-z .'-]+$/i";
if(!preg_match($string_validate,$name)) {
$error_message .= "The name is invalid.<br /><br />";
}
if(strlen($message) < 2) {
$error_message .= "The message is invalid.<br />";
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Name: ".$name."\n";
$email_message .= "Email: ".$email_from."\n";
$email_message .= "Message: ".$message."\n";
mail($email_to, $email_subject, $email_message);
echo "Thank you, your message has been sent. We will reply to you as soon as we can.";
}
?>
</span>
</span>
<a href="services.htm" onclick="return(xr_nn());">
<img class="xr_ap" src="index_htm_files/127.png" alt="" title="" onmousemove="xr_mo(this,0,event)" style="left: 15px; top: 381px; width: 62px; height: 23px;"/>
</a>
<span class="xr_s5" style="position: absolute; left:32px; top:26px;">
<span class="xr_tl" style="top: -14px;">Welcome</span>
</span>
<img class="xr_ap" src="index_htm_files/128.png" alt="" id="sdbanner" title="" style="left: 15px; top: 38px; width: 770px; height: 177px;"/>
<span class="xr_s0" style="position: absolute; left:32px; top:183px;">
<span class="xr_tl" style="top: -11px;"> Quality Web Design is our Trademark</span>
</span>
<a href="index.htm" target="_self" onclick="return(xr_nn());">
<img class="xr_ap" src="index_htm_files/8.png" alt="" title="" onmousemove="xr_mo(this,0,event)" style="left: 15px; top: 37px; width: 49px; height: 30px;"/>
</a>
<a href="services.htm" target="_self" onclick="return(xr_nn());">
<img class="xr_ap" src="index_htm_files/9.png" alt="" title="" onmousemove="xr_mo(this,0,event)" style="left: 63px; top: 37px; width: 63px; height: 30px;"/>
</a>
<img class="xr_ap" src="index_htm_files/139.png" alt="" title="" style="left: 125px; top: 37px; width: 59px; height: 30px;"/>
<a href="clients.htm" target="_self" onclick="return(xr_nn());">
<img class="xr_ap" src="index_htm_files/140.png" alt="" title="" onmousemove="xr_mo(this,0,event)" style="left: 184px; top: 37px; width: 54px; height: 30px;"/>
</a>
<img class="xr_ap" src="index_htm_files/12.png" alt="" title="" style="left: 72px; top: 58px; width: 126px; height: 126px;"/>
<img class="xr_ap" src="index_htm_files/136.png" alt="" title="" style="left: 15px; top: 412px; width: 191px; height: 2px;"/>
<span class="xr_s0" style="position: absolute; left:15px; top:433px;">
<span class="xr_tl" style="top: -11px;"><span class="xr_s1">Clients</span></span>
<span class="xr_tl" style="top: 4px;">Steadfast Design is proud to have </span>
<span class="xr_tl" style="top: 20px;">created high quality websites for our </span>
<span class="xr_tl" style="top: 35px;">clients. Please click to view some </span>
<span class="xr_tl" style="top: 50px;">examples of our work</span>
</span>
<a href="clients.htm" onclick="return(xr_nn());">
<img class="xr_ap" src="index_htm_files/114.png" alt="" title="" onmousemove="xr_mo(this,0,event)" style="left: 15px; top: 505px; width: 54px; height: 23px;"/>
</a>
<a href="index.htm" onclick="return(xr_nn());">
<img class="xr_ap" src="index_htm_files/120.png" alt="" title="" onmousemove="xr_mo(this,0,event)" style="left: 15px; top: 274px; width: 60px; height: 23px;"/>
</a>
<span class="xr_s0" style="position: absolute; left:15px; top:234px;">
<span class="xr_tl" style="top: -11px;"><span class="xr_s1">Home Page</span></span>
<span class="xr_tl" style="top: 4px;">Click here to return to the main page of </span>
<span class="xr_tl" style="top: 20px;">Steadfast Design</span>
</span>
<img class="xr_ap" src="index_htm_files/141.png" alt="" title="" style="left: 125px; top: 37px; width: 59px; height: 30px;"/>
<div id="xr_xo0" class="xr_ap" style="left:0; top:0; width:800px; height:100px; visibility:hidden;">
<a href="" onclick="return(false);">
<img class="xr_ap" src="index_htm_files/130.png" alt="" title="" style="left: 15px; top: 381px; width: 62px; height: 23px;"/>
<img class="xr_ap" src="index_htm_files/15.png" alt="" title="" style="left: 15px; top: 37px; width: 49px; height: 30px;"/>
<img class="xr_ap" src="index_htm_files/16.png" alt="" title="" style="left: 63px; top: 37px; width: 63px; height: 30px;"/>
<img class="xr_ap" src="index_htm_files/141.png" alt="" title="" style="left: 125px; top: 37px; width: 59px; height: 30px;"/>
<img class="xr_ap" src="index_htm_files/142.png" alt="" title="" style="left: 184px; top: 37px; width: 54px; height: 30px;"/>
<img class="xr_ap" src="index_htm_files/119.png" alt="" title="" style="left: 15px; top: 505px; width: 54px; height: 23px;"/>
<img class="xr_ap" src="index_htm_files/121.png" alt="" title="" style="left: 15px; top: 274px; width: 60px; height: 23px;"/>
</a>
</div>
<div id="xr_xd0"></div>
</div>
</div>
<!--[if lt IE 7]><script type="text/javascript" src="index_htm_files/png.js"></script><![endif]-->
<script type="text/javascript">xr_aeh()</script>
</body>
</html>
Thanks,
Roy