jha900 Posted June 12, 2008 Share Posted June 12, 2008 I have a contact us.php that works but after the user enters the information and presses "Submit" they don't go back to the Contact Us page. What code do I put in the html to make it go back to the Contact Us page or the home page? Thanks Link to comment https://forums.phpfreaks.com/topic/109948-php-contact-us-form/ Share on other sites More sharing options...
DyslexicDog Posted June 12, 2008 Share Posted June 12, 2008 You could add a meta refresh tag to the submit page or you could use the php header() function to achieve the same functionality. Link to comment https://forums.phpfreaks.com/topic/109948-php-contact-us-form/#findComment-564207 Share on other sites More sharing options...
revraz Posted June 12, 2008 Share Posted June 12, 2008 Header won't work since his form displays output. HTML or javascript would be the best way. Link to comment https://forums.phpfreaks.com/topic/109948-php-contact-us-form/#findComment-564212 Share on other sites More sharing options...
phpSensei Posted June 12, 2008 Share Posted June 12, 2008 <script type="text/javascript"> <!-- window.location = "http://www.google.com/" //--> </script> Link to comment https://forums.phpfreaks.com/topic/109948-php-contact-us-form/#findComment-564215 Share on other sites More sharing options...
Rayhan Muktader Posted June 12, 2008 Share Posted June 12, 2008 Header won't work since his form displays output. HTML or javascript would be the best way. How do you know if the form displays output? Did you mean errors and warnings if invalid input is entered? Try putting this on the very top of the page: if(!isset($_POST['submit'])) { // first validate the form // then save the form in the database. if( form validates without errors) { header ("Location: http://" . $_SERVER['HTTP_HOST']); exit(); } } Link to comment https://forums.phpfreaks.com/topic/109948-php-contact-us-form/#findComment-564220 Share on other sites More sharing options...
jonsjava Posted June 12, 2008 Share Posted June 12, 2008 Here's how I do mine. You may be able to use it just fine: <form method="POST" action="p_contact.php"> <center> <h3>Contact Us</h3> <table border="0"> <tr> <td>Your Name:</td> <td><input type="text" name="name" size="56"></td> </tr> <tr> <td>E-Mail Address:</td> <td><input type="text" name="email" size="56"></td> </tr> <tr> <td>Contact Reason:</td> <td><select name="reason"> <option value="1" selected="selected">Need assistance with a script you made</option> <option value="2">Need Assistance with a script I made</option> <option value="3">Looking for help with an open-source project</option> <option value="4">Wanted to thank you for all you've done</option> <option value="5">Offering assistance with one of your open-source projects</option> <option value="6">Just saying "Hi"/Other</option> </select> </td> </tr> <tr> <td>Subject:</td> <td><input type="text" name="subject" size="56"></td> </tr> <tr> <td>Message:</td> <td><textarea name="body" cols="42" rows="10"></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" value="Submit"></td> </tr> </table> </form> and my p_contact.php page: <?php $reason_array = array("Need assistance with a script you made", "Need Assistance with a script I made", "Looking for help with an open-source project", "Wanted to thank you for all you've done", "Offering assistance with one of your open-source projects", "Just saying \"Hi\"/Other"); $reason = $_POST['reason']; $contact_reason = $reason_array[$reason -1]; $subject = $_POST['subject']; $body = $_POST['body']; $email = $_POST['email']; $name = $_POST['name']; $to = "[email protected]"; $subject = $_POST['subject']; $message = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html> <head> <title>".$subject."</title> </head><center>Contact Reason: $contact_reason</center><br />\n <strong>Name:</strong>$name<br />\n"; $message_clean1 = str_replace("\'", "'", $_POST['body']); $message_clean2 = str_replace('"', "'", $message_clean1); $message_clean3 = str_replace("\v", "", $message_clean2); $message_clean4 = str_replace("\'", "'", $message_clean3); $message .= $message_clean4; $message .= "<br /><br /><br />"; $message .= "\n</body></html>"; include("MIME.class.php"); $mime = new MIME_mail($email, $to, $subject); $mime->attach($message, "", HTML, BASE64); $mime->send_mail(); header("location:contact_us.php"); exit(); ?> *Edit forgot. Mine uses the Mime mail class. If you want to use my method, you'll need to get that from PHPGuru.org. Link to comment https://forums.phpfreaks.com/topic/109948-php-contact-us-form/#findComment-564226 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.