HTML5 AJAX Responsive Contact Form With Google Maps

HTML5 AJAX Responsive Contact Form With Google Maps

In this post we will discuss how to create a HTML5 AJAX Responsive Contact Form With Google Maps.I am using PHP as back end technology but you can use what ever you want.
We are doing form validation in both HTML5 as well as jQuery(JavaScript) level but if you want you can also write them for back end level also.

Index.Html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>HTML5 AJAX Responsive Contact Form with Google Maps</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="description" content="">
    <meta name="author" content="">
    <!-- LOAD CSS FILES -->
    <link href="css/main.css" rel="stylesheet" type="text/css">
    
    <!-- LOAD JS FILES -->
   	<script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.isotope.min.js"></script>
	<script src="js/contact.js"></script>
    
</head>
<body>
    <!-- subheader begin -->
	<div id="subheader">
    	<div class="container">
    	  <div class="row">
          	<div class="span12">
                  <br />
            	<h1 style="padding:10px;text-align:center">HTML5 AJAX Responsive Contact Form with Google Maps</h1>
                <br /><br />
            </div>
          </div>
    	</div>
    </div>
	<!-- subheader close -->  
        
   <div id="map-container">
    <iframe width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Qutub+Minar+Delhi,+Seth+Sarai,+Mehrauli,+New+Delhi,+Delhi,+India&amp;aq=3&amp;oq=quta&amp;sll=37.0625,-95.677068&amp;sspn=41.95363,86.572266&amp;ie=UTF8&amp;hq=&amp;hnear=Qutub+Minar,+Kalu+Ram+Rd,+Seth+Sarai,+Mehrauli,+New+Delhi,+South+Delhi,+Delhi+110016,+India&amp;t=m&amp;z=14&amp;ll=28.526407,77.187028&amp;output=embed"></iframe>
   </div>
    
	<!-- content begin -->
    <div id="content" style="padding:10px">
    	<div class="container">
        	<div class="row">
            	<div class="span8">
                	<h4>Get in touch with us now!</h4>
Feel free to contact us by contact to get more information.<br/><br/>
                	<div class="contact_form_holder">
              <form id="contact" class="row" name="form1" method="post" action="">
              
       			<div class="span2">
                <label>Name <span class="req">*</span></label>
           		<input type="text" class="full" name="name" id="name"/>
                <div id="error_name" class="error">Please check your name</div>
           		</div>

                <div class="span2">
                <label>Phone <span class="req">*</span></label>
           		<input type="text" class="full" name="phone" id="phone"/>
                <div id="error_phone" class="error">Please check your phone</div>
           		</div>
                
                <div class="span4">
                <label>Email <span class="req">*</span></label>
           		<input type="text" class="full" name="email" id="email"/>
                <div id="error_email" class="error">Please check your email</div> 
				</div>
				
                <div class="span8">
                <label>Message <span class="req">*</span></label>
                <textarea cols="8" rows="10" name="message" id="message" class="full"></textarea>
                <div id="error_message" class="error">Please check your message</div>
                <div id="mail_success" class="success"> Thank you. Your message has been sent.</div>
<div id="mail_failed" class="error">Error, email not sent</div>

<p id="btnsubmit"><input type="submit" id="send" value="Send" class="btn btn-large"/></p>               
                </div>              
              </form>
            </div>
            
                </div> 
                    
              <div id="sidebar" class="span4">
              		
<div class="widget latest_news">
                    	<h4 class="title">Reach Us</h4>

                    </div>
              
       	  <div class="widget widget-text">
                	<h4 class="title">Other Details:</h4>
                	<strong>
                      	</strong>
       	  </div>
              </div>
     	</div>
</div>
</div>
</body>
</html>

Contact.js

    $(document).ready(function(){
      $("#send").click(function(){
          var name = $("#name").val();
          var phone = $("#phone").val();
        var email  = $("#email").val();
        var message  = $("#message").val();

        var error = false;
         
        if (name.length == 0) {
            var error = true;
            $("#error_name").fadeIn(500);
        }
        else {
            $("#error_name").fadeOut(500);
        }

        if (phone.length == 0) {
            var error = true;
            $("#error_phone").fadeIn(500);
        }
        else {
            $("#error_phone").fadeOut(500);
        }

         if(email.length == 0 || email.indexOf("@") == "-1" || email.indexOf(".") == "-1"){
           var error = true;
           $("#error_email").fadeIn(500);
         }
         else {
           $("#error_email").fadeOut(500);
         }
         
         if(message.length == 0){
            var error = true;
            $("#error_message").fadeIn(500);
         }else{
            $("#error_message").fadeOut(500);
         }
         
         if(error == false){
           $("#send").attr({"disabled" : "true", "value" : "Loading..." });
            
           $.ajax({
             type: "POST",
             url : "send.php",    
             data: "name=" + name + "&email=" + email + "&subject=" + "You Got Email" + "&message=" + message,
             success: function(data){    
              if(data == 'success'){
                $("#btnsubmit").remove();
                $("#mail_success").fadeIn(500);
              }else{
                $("#mail_failed").html(data).fadeIn(500);
                $("#send").removeAttr("disabled").attr("value", "send");
              }     
             }  
           });  
        }
		    return false;                      
      });    
    });

Send.php

<?php
session_start();

    $email_to = "info@hightechnology.in"; // change with your email
    $name     = $_POST['name'];
    $phone    = $_POST['phone'];
    $email    = $_POST['email'];
    $subject   = $_POST['subject'];
    $message    = $_POST['message'];
    
    $headers  = "From: $email\r\n";
    $headers .= "Reply-To: $email\r\n";
    
    if(mail($email_to, $subject, $message, $headers)){
        echo "success";       
    } 
    else{
        echo "failed";     
    }  
?>