Solved

html contact form submit thank you message

Posted on 2013-02-06
2
351 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hit counters in SharePoint 2013 2 61
Why does my submit button remain disabled 3 34
NOT having JQuery DataTable Columns Sort 7 35
Difference between Leaflet and MapBox? 5 45
Find out what you should include to make the best professional email signature for your organization.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

732 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