Jump to content

“Contact Me” form Question


jcb9119
 Share

Recommended Posts

I included only a fraction of my Contact Me page and form handler in an attempt to simplify this question.Basically, php begins by presenting a form to the user. The user enters a couple fields then presses enter to submit their comments in an email. After the email is sent I would like to pop-up an alert thanking the user. After the user clicks “OK” on the alert, I want to transfer the user to my index.php landing page. The problem is, when I UNcomment the header("Location: index.php"); code at the bottom of the form handler, php simply executes it and the user is never prompted with the alert.I would like the alert to stop and display on the screen before the user is eventually transferred to index.php. Will someone please help?Here is the form code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head></head><body> <div id="main_area" style="margin:0;padding:0;background:#FFFF00" > <h2 style="padding-left:1px;text-align:center;">     Contact Us</h2> <fieldset style="border: 5px ridge;color:indigo; width:99%"> <legend </font> <!-- This form transmits an email --> </legend> <form action="question_form_handle.php" method="post" style="background-color:#996633;width 530px;" ><!-- Name --> Enter Your Name: <br /> <input type="text" name="persons_name" size="30" /> <br /> <br /> <!-- Email Address --> Your Email Address: <br /> <input type="text" name="client_email" size="30" /> <br /> <br /> <!-- Message Subject --> The Subject: <br /> <input type="text" name="subject" size="30" /> <br /> <br /><!-- Text Area --> The Message: <br /> <textarea rows="8" cols="40" name="message_text" />Type Your Message in this area, then Click the "Submit Email" button below...</textarea> <br /> <br /> </fieldset> <br /> <input type="submit" value="Submit Email" /> </form> </div> <!-- closing div of the main area --> <?php /* include("footer.inc.php") */ ?> </div> <!-- closing div of nav_container --> </div> <!--closing div tag of the "screen_container" --></body></html>The form handler is pasted below (question_form_handle.php)<?php$persons_name = $_POST['persons_name'] ;$client_email = $_POST['client_email'] ;$subject = $_POST['subject'] ;$email_address = "anemail@emailaddress.com";// commented code $email_address = retrieveEmailAddress();$message_text = $_POST["message_text"] ;echo "<br />";echo "<br />";$message_text = "This message was sent by:<br />" . $persons_name . "<br /> <br />" . "Who indicated their email address is:<br />" . $client_email . "<br /><br />" . "Their message reads:" . "<br />" . $message_text;// mail($email_address,$subject,$message_text);//header("Location: index.php");?> <script type="text/javascript">alert("Thank You for your feedback! We will review it as soon as possible and contact you if we need more info.");</script><?php/* COMMENTED header("Location: index.php"); */?>

Link to comment
Share on other sites

That's the way a location header works. In this case, you send a document to the browser. It contains a script, and that is all, but it is still a document. When the browser receives the location header, it goes out and gets a new document at the location URL. All of this happens so quickly that there is no time for the alert to fire. The second document replaces the first document almost immediately.To do what you want, index.php will have to include the alert statement.But please don't use an alert statement. Users hate them. I hate them. Don't you hate them?

Link to comment
Share on other sites

You just needs to modify your javascript alert with below code,<script type="text/javascript">alert("Thank You for your feedback! We will review it as soon as possible and contact you if we need more info.");</script>Instead,<script type="text/javascript">if(alert("Thank You for your feedback! We will review it as soon as possible and contact you if we need more info.")){ window.location="index.php"; return true;}return false;</script>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...