Hi All,

New to the world of PHP and such, and took on a project that I really should have farmed out, but too late now.

Here is my question: the problem is the redirect for an error message in a contact us page. I have very specific standards set for the look of the site and have to stick to it. Below is the code:

<?php 
$admin_email = "xxxx.com"; 

if(isset($_POST['submit_msg'])) 
{ 
   if (empty($HTTP_POST_VARS['name_msg'])){ 
      die('<p><p><center><h3><i>Error!</i></h3><br>CAUTION : PLEASE TYPE YOUR NAME IN THE FORM</font><br><br><span style="cursor:hand" ONCLICK="window.history.go(-1);">BACK TO FORM</span><center>'); 
   }; 
   if (empty($HTTP_POST_VARS['email_msg'])){ 
      die('<p><p><center><h3><i>Error!</i></h3><font color="#ff0000"> <br>CAUTION : PLEASE TYPE YOUR EMAIL IN THE FORM<br><br><span style="cursor:hand" ONCLICK="window.history.go(-1);">BACK TO FORM</span><center>'); 
   }; 
   if (empty($HTTP_POST_VARS['msg_body'])){ 
      die('<p><p><center><h3><i>Error!</i></h3><font color="#ff0000"> <br>CAUTION : PLEASE TYPE YOUR MESSAGE IN THE FORM</font><br><br><span style="cursor:hand" ONCLICK="window.history.go(-1);">BACK TO FORM</span><center>'); 
   }; 

   $name_msg = htmlspecialchars($HTTP_POST_VARS['name_msg']); 
   $name_msg = str_replace("&amp;","&",$name_msg); 
   $name_msg = str_replace("ی","ي",$name_msg); 

   $msg_body = htmlspecialchars($HTTP_POST_VARS['msg_body']); 
   $msg_body = str_replace("&amp;","&",$msg_body); 
   $msg_body = str_replace("ی","ي",$msg_body); 
   $msg_body = nl2br($msg_body); 

      if (!empty($HTTP_POST_VARS['lvl_msg'])) 
      { 
         $lvl_msg  = str_replace('http://','',$_POST['lvl_msg']); 
		 $lvl_msg = str_replace("&amp;","&",$lvl_msg); 
		 $lvl_msg = str_replace("ی","ي",$lvl_msg); 
      } 

         if(!strpos($_POST['email_msg'],"@")) 
         { 
            print('<p><p><center><h3><i>Error!</i></h3><br>CAUTION : PLEASE TYPE YOUR EMAIL<br><br><span style="cursor:hand" ONCLICK="window.history.go(-1);">Back to form</span><center>'); 
            die('<br><br><center>EXAMPLE : admin@xxxxxxxxxxxxxx.com </center>'); 
         }; 

      $from  = htmlspecialchars($HTTP_POST_VARS['email_msg']); 
      $body = '<html>
<head>
<title>Contact Us</title>

</head> 
<body> 
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">=&gt; NEW COMMENT &lt;=</td>
</tr>
<tr>

<td width="100%">NAME AND USER LEVEL</td>
<td width="100%" align="left">'.$name_msg.'</td>
</tr>
<tr>
<td width="100%" dir="rtl">COMMENT</td>
<td width="100%" align="left">'.$msg_body.'</td>
</tr>
</table> 
</body> 
</html>'; 
if(!mail($admin_email,'NEW CONTACT',$body,"From: <$from>\n"."MIME-Version: 1.0\n"."Content-type: text/html")) 
{ 
[B] print('<p><p><center>><h3><i>THE EMAIL COULD NOT BE SENT!</i></h3> <br>SERVER IS BUSY, PLEASE TRY LATER<br><br><span style="cursor:hand" ONCLICK="window.history.go(-1);">RETURN TO FORM</span></center></p></p>'); [/B]
}else 
{ 
[B]   print('<p><p><center>><h3><i>Thank You!</i></h3> <br>YOUR COMMENT HAS BEEN SENT SUCCESSFULLY!<br>THANKS FOR YOUR COMMENT<br><br><span style="cursor:hand" ONCLICK="window.history.go(-1);"> RETURN TO HOME PAGE </span><center>'); 
} [/B]

}
else 
{ 
?> 
<html>
<head>
<title>Contact Us</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Language" content="fa">
<meta name="Geo.Country"        content="IR">
<meta name="Robots"             content="all">
<meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0)">
<meta http-equiv="Page-Exit" content="blendTrans(Duration=1.0)">
</head>
<body>
<div id="mainContent">
  <div id="pageContent">
    <table>
     <caption>
        CONTACT US
      </caption>
     
      <td align="center">YOUR CONCERNS ARE OUR CONCERNS </td>
        <tr>
        <td><p align="left"><span lang="en-ca" dir="ltr">While we are very diligent in keeping the website up to our standards, we sometimes lose sight of what's most important to our friends and advertisers. If you have a concern, please use this form to voice your opinion to us. We will look into the matter, and get right on it if it is merited. We will respond to you with our decision in the matter.</p> 
        <p>Please feel free to use this form for any questions or just to say "HI" to the xxxxxxxxxxxxxxx Team. We appreciate you and would like to hear from you no matter what the topic.</p>
        <p>Thank you for you patronage, and enjoy our community.</p>	
        <p>xxxxxxxxxxxxxx Team</p></span></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
</table>
<td>&nbsp;</td>
<td valign="top"><form name="msg_form" method="POST" > 
<table border="0" width="86%" cellspacing="0" cellpadding="0" id="fa" height="201">
<tr>
<td width="500" dir="rtl" align="left"><span dir="ltr">Your Name<input name="name_msg" size="60" id="fa" dir="ltr" tabindex="1" maxlength="60" lang="fa" style="float: left" value="" onClick="this.value=''"> 
*: </span> </td></tr><tr>
<td width="500" dir="rtl" align="left"><span dir="ltr">Username (or Guest)<input name="lvl_msg" size="60" dir="ltr" tabindex="2" maxlength="60" id="fa" style="float: left" value="" onClick="this.value=''"> :
</span> </td></tr>
<tr>
<td width="500" dir="rtl" align="left"><span dir="ltr">Your Email<input name="email_msg" size="60" dir="ltr" tabindex="3" maxlength="60" id="fa" style="float: left" value="" onClick="this.value=''"> *:
</span> </td></tr>
<tr>&nbsp; &nbsp;
<td width="500" dir="rtl" align="left"><span dir="ltr">Your Request*:<textarea rows="6" name="msg_body" cols="53" dir="ltr" id="fa" tabindex="4" lang="fa" onClick="this.value=''"></textarea>
</span> </td></tr>
<tr><td>
<span dir="ltr">
<input type="submit" value="Submit" name="submit_msg" tabindex="5" id="fa" float="left" ></span></td>
<td width="127">&nbsp;</td></tr>
</table>
</td></form>
<td width="386" height="207">&nbsp;</td>
</tr>
</table>
</div>

At first, it kept overwriting my CSS, but I figured that out quickly enough. Now it redirects to an error page, or a success page, but I'm having trouble with getting it to direct (see emboldened part of code) itself to a specific page (error_contact_us.php, or successful_contact.php) and be able to return to the contact us page (if an error), or if successful hold the success page up for 15 seconds and then redirect to the home page. I'm just not savvy enough with php to know how to do what is probably a very simple task.

Any help you can give me would be greatly appreciated;.

Ron

Okay, gotta add this to this thread since they're related:

I'm having the same problem with the login, logout, and register scripts... I can't seem to get them to play nicely with the html/CSS of the site I'm building... can anyone help with how I should place the script on the page?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.