Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

html contact form submit thank you message

Posted on 2013-02-06
2
Medium Priority
?
362 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 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.

Cd&
0
 
LVL 1

Author Closing Comment

by:tf2012
ID: 38865276
thanks!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

636 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