Bruno41 Posted August 26, 2009 Share Posted August 26, 2009 Hello, I am a PHP novice. Below is the code to a contact form on my website. The page works and submits email fine, but when the screen returns after you hit the submit button, the screen is all messed up. The page loads correctly and looks fine on the initial load, its only after you hit submit that it returns incorrectly. The left side of the page ends up underneath the rest. I've tried everything to fix it. Please help! <?php // Insert Company Info Variables: DO NOT REMOVE require_once('inc_companyInfo.php'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title><?php echo"$companyName";?></title> <?php // Insert description and keywords, these can be removed and your own added if you like require_once('inc_description.php'); require_once('inc_keywords.php'); ?> <?php // Insert Style Sheet and JavaScripts: DO NOT REMOVE require_once('inc_styleJs.php'); ?> </head> <body onLoad="P7_initPM(0,19,1,0,10);P7_equalCols2(1,'sidebox','P','centerwrapper','P')"> <div id="skiplinks"> <a href="#p7PMnav">Skip to navigation</a></div> <div id="layoutwrapper"> <div id="centerwrapper"> <div id="masthead"> <div id="logodiv"><img src="images/jazz_logo.jpg" width="340" height="150"></div> </div> <div id="centerbox"> <div id="centercontent"> <table border="0" cellpadding="0" cellspacing="0" class="formTable"> <tr> <td><h1>Contact Us </h1> <p>We welcome the chance to speak with you regarding your needs and how we can assist you. Please feel free to contact us via mail, phone or email using the contact form below.</p><td width="150" rowspan="2" valign="top"><img src="images/Woman-Computer-support.jpg" width="216" height="173" hspace="10" border="1" align="right" title="Contact us today to see how we can help you with your billing needs."></td> </tr> <p> <?php $subject = $_GET['sub']; $posted = isset ($_POST['submit']); // Declare Variables $name = stripslashes($_POST['name']); $phone = stripslashes($_POST['phone']); $email = stripslashes(trim($_POST['email'])); $comments = stripslashes($_POST['comments']); $to = "$companyEmail"; // Insert Spam check function to stop bots, do not remove. require_once('spam_check.php'); spamcheck($subject); spamcheck($name); spamcheck($phone); spamcheck($comments); // Basic HTML formatting stuff. if (!$posted) { print '<form name="contact" method="post" action="contact.php"> <p >Please note that <b>bold</b> fields are required.</span></p> <table width="100%" border="0" cellpadding="5" cellspacing="0" class="formTBOut"> <tr class="worksheetHead"> <td colspan="2" class="worksheetHead">Contact Form</td> </tr> <tr> <td width="75" > <div align="right">Subject:</div></td> <td><input name="subject" type="text" size="50" value="'. $subject .'"></td> </tr> <tr> <td width="75" > <div align="right">Name:</div></td> <td><input name="name" type="text" size="50"></td> </tr> <tr> <td width="75" > <div align="right">Phone:</div></td> <td><input name="phone" type="text" size="50"></td> </tr> <tr> <td width="75" > <div align="right"><b>Email:<b></div></td> <td><input name="email" type="text" size="50"></td> </tr> <tr> <td width="75" > <div align="right">Comments:</div></td> <td><textarea name="comments" cols="40" rows="5"></textarea> </td> </tr><tr> <td width="75" > </td> <td><input name="submit" type="submit" value="Submit"> <input name="clear" type="reset" value="Clear Form"></td> </tr> </table> </form>'; } if ($posted) { $subject = $_POST['subject']; // set subject line. $problem = FALSE; // Set no problems found if (!eregi("^[[:alnum:]][a-z0-9_._]*@[a-z0-9.-]+\.[a-z]{2,4}$", $email)) { // Checks for valid email $problem = TRUE; // Declare a problem echo '<form name="contact" method="post" action="contact.php"> <p class="errorMessage"><b>Warning: Your message was not sent!</b><br />Error Found: Valid email address not entered.</p> <table width="100%" border="0" cellpadding="5" cellspacing="0" class="formTBOut"> <tr class="worksheetHead"> <td colspan="2" class="worksheetHead">Contact Form</td> </tr> <tr> <td width="75" > <div align="right">Subject:</div></td> <td><input name="subject" type="text" size="50" value="'. $subject .'"></td> </tr> <tr> <td width="75" class="formText">Name:</td> <td><input name="name" type="text" size="50" value="' . $name . '"></td> </tr> <tr> <td width="75" class="formText">Phone:</td> <td><input name="phone" type="text" size="50" value="' . $phone . '"></td> </tr> <tr> <td width="75" class="error"><b>* Email:<b></td> <td><input name="email" type="text" size="50" class="errorInput" value="'. $email .'"></td> </tr> <tr> <td width="75" class="formText">Comments:</td> <td><textarea name="comments" cols="40" rows="5">'. $comments .'</textarea> </td> </tr> <tr> <td width="75" class="formText"> </td> <td><input name="submit" type="submit" value="Submit" class="formButton"> <input name="clear" type="reset" value="Clear Form" class="formButton"></td> </tr> </table> </form>'; } if (!$problem) { print '<span >Your message has been sent to <a href="mailto:'. $to .'">'. $to .'</a>. We will respond to your request if needed within two business days.</span>'; // Check if subject is NULL, if it is set it if (!$subject) { $subject = "$companyName Contact Form"; } // Set Body of Email $body = ''. $companyName .' Contact Form'; $body .= " Name: $name Phone: $phone Email: $email Comments: $comments"; // Send Email mail($to, ''. $subject .'', $body, "From: $email"); } } ?> </div> <div id="centerbottom"> <div id="centerbottominfo"><img src="images/jazz_bottomleft.jpg" width="300" height="32"></div> </div> </div> </div> <div id="sidebox"> <div id="sidebar"> <div id="menubar"> <?php // Insert Navigation: DO NOT REMOVE require_once('inc_nav.php'); ?> </div> <div id="sidecontent"> <?php // Insert Side Contact: DO NOT REMOVE require_once('inc_contact.php'); ?> </div> </div> </div> <div id="footer"> <?php // Insert Footer require_once('inc_footer.php'); ?> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/172046-help-with-screen-returning-from-email-submit/ Share on other sites More sharing options...
oni-kun Posted August 27, 2009 Share Posted August 27, 2009 PHP will display the form, and when you hit submit it will place your 'Successful!'/'Failure!' message injected where the form was supposed to be, look at your HTML after submitting and you'd see it's doubled from each one.. I'd recommend header();ing to contact_us.php?submitted=true or similar, and that would cause the form not to exist, and the 'sent/fail' message to be there in place. Quote Link to comment https://forums.phpfreaks.com/topic/172046-help-with-screen-returning-from-email-submit/#findComment-907174 Share on other sites More sharing options...
Bruno41 Posted August 27, 2009 Author Share Posted August 27, 2009 Thanks! So you are recommending putting the header function before the success / failure message? Quote Link to comment https://forums.phpfreaks.com/topic/172046-help-with-screen-returning-from-email-submit/#findComment-907220 Share on other sites More sharing options...
oni-kun Posted August 27, 2009 Share Posted August 27, 2009 Thanks! So you are recommending putting the header function before the success / failure message? Well yes, you'd write something like this.. so if they were sent to.. contact_us.php?sent=success it'd say.. if (isset($_GET['sent'])){ if ($_GET['sent']=="success") { echo "Message sent successfully!"; } else { echo "Message failed, please check your boxes"; } } Or something of the sort.. Quote Link to comment https://forums.phpfreaks.com/topic/172046-help-with-screen-returning-from-email-submit/#findComment-907228 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.