Solved

html contact form submit thank you message

Posted on 2013-02-06
2
335 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
2 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
Comment Utility
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
Comment Utility
thanks!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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…
The viewer will learn how to dynamically set the form action using jQuery.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now