Solved

html contact form submit thank you message

Posted on 2013-02-06
2
347 Views
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) {											
		
									emailFailed="1";											
		
								}
		
								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;
		
								}										
		
							}
		
						</script>
			
				</form><!--#form -->

Open in new window

And here is the sendForm.php code
<?php 
//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))) {
   echo("
<p>Message delivery failed...</p>
 
");
   echo("from email: $fromemail to email: $toemail");
  }
//-----------------End send email script------------------------

?>

Open in new window

0
Comment
Question by:tf2012
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 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.

Cd&
0
 
LVL 1

Author Closing Comment

by:tf2012
ID: 38865276
thanks!
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…

761 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