html contact form submit thank you message

Posted on 2013-02-06
Medium Priority
Last Modified: 2013-02-07
I'd like to either use jquery or javascript to show a div or pop a message when the form has been submitted to the php handler.

I've googled it and the examples seem to be pretty confusing.  Below is my form and my form php code.  Can anyone recommend a current best practice method for showing an acknowledgement that the form has been submitted?

Plus my current way of doing this opens sendForm.php and doesn't return the user to the form page... not sure how to do that either in case someone knows how to do that.  Kind of lost here.

					<form action="sendForm.php" name="leadForm" method="post"  onsubmit="return validateMainForm();">
							<div class="inputRow">	
								<label for="nameField">Name:</label>
								<input maxlength="40" name="nameField" type="text" class="ContactFormTextInput" id="nameField" />
							</div><!-- inputRow -->
							<div class="inputRow">
								<label for="phoneField">Phone:</label>
								<input maxlength="40" name="phoneField" type="text" class="rightColumnContactFormTextInput" id="phoneField" />							
							</div><!-- inputRow -->
							<div class="inputRow">
								<label for="emailField">Email:</label>
								<input maxlength="100" name="emailField" type="text" class="rightColumnContactFormTextInput" id="emailField" />
							</div><!-- inputRow -->
							<div class="inputTextArea">
								<label for="messageField">Details:</label>
									<textarea cols="29" name="messageField" id="messageField"></textarea>
							</div><!-- inputRow -->
						<input name="submit" type="submit" value="Send" class="button" />
						<script type="text/javascript">
							function validateMainForm() {
								//super simple email validator Nov 11, 2011
								var nameMainForm=document.forms["leadForm"]["nameField"].value;
								var emailMainForm=document.forms["leadForm"]["emailField"].value;
								var phoneMainForm=document.forms["leadForm"]["phoneField"].value;
								//validate email string
								var atpos=emailMainForm.indexOf("@");
								var dotpos=emailMainForm.lastIndexOf(".");
								var emailFailed="0"; //good email = 0
								if (atpos<1 || dotpos<atpos+2 || dotpos+2>=emailMainForm.length) {											
								if ((nameMainForm==null || nameMainForm=="")||(phoneMainForm==null || phoneMainForm=="")) {
									alert("Please complete all fields in the form.");
									return false;
								} else if (emailFailed=="1") {
									alert("Please include a valid email address");
									return false;
				</form><!--#form -->

Open in new window

And here is the sendForm.php code
//Email address of person who should get email notification of form submission
$toemail = "mymail@here.com";
//-----------------Start send email script------------------------
//This is where you would put any custom scripting such as using php to send confirmation emails
$fromemail = "mail@mymail.com";
$subject = " Quote Request";
$body = "Name: ".$_POST['nameField']."\r\n"."Email: ".$_POST['emailField']."\r\n"."Phone: ".$_POST['phoneField']."\r\n"."Request Details: ".$_POST['messageField']."\r\n";
$header = "From: " . $fromemail . "\r\n";
$header .= "Reply-To: " . $fromemail . "\r\n";
if (!(mail($toemail,$subject,$body,$header))) {
<p>Message delivery failed...</p>
   echo("from email: $fromemail to email: $toemail");
//-----------------End send email script------------------------


Open in new window

Question by:tf2012
LVL 53

Accepted Solution

COBOLdinosaur earned 2000 total points
ID: 38861945
Well unless you server is really slow, the server will have a response back very quickly, and telling them it is sent should not be necessary.  When they submit the form, the next thing they should see is the response page with a thank you and confirmation; or an error message that tells them what they need to fix.


Author Closing Comment

ID: 38865276

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question