php - Code to submit the email form without refreshing the page and without validation -


i have created contact form using requires attribute. want submit email form without refreshing page. when googled it, got validation code, don't need validation because used required attribute in html. want function can add page wont refreshed after submitting , email should go..

index.html

<!doctype html> <html>       <head>         <meta charset="utf-8">         <title>html5 contact form</title>         <link rel="stylesheet" media="screen" href="styles.css">     </head>          <body>         <div id="contact">             <form class="contact_form" action="contact.php" method="post" name="contact_form">                 <ul>                     <li>                          <h2>contact us</h2>                          <span class="required_notification">* denotes required field</span>                      </li>                     <li>                         <label for="name">name:</label>                         <input type="text" id="name" name="name" placeholder="john doe" required />                     </li>                     <li>                         <label for="email">email:</label>                         <input type="email" name="email" id="email" placeholder="john_doe@example.com" required /> <span class="form_hint">proper format "name@something.com"</span>                      </li>                     <li>                         <label for="message">message:</label>                         <textarea name="message" id="message" cols="40" rows="6" required></textarea>                     </li>                     <li>                         <button class="submit" id="submit_btn" type="submit">submit form</button>                     </li>                 </ul>             </form>         </div>     </body> </html> 

contact.php

<?php     $field_name = $_post['name'];     $field_email = $_post['email'];     $field_message = $_post['message'];     $mail_to = 'babloopuneeth@gmail.com';     $subject = 'message site visitor '.$field_name;     $body_message = 'from: '.$field_name."\n";     $body_message .= 'e-mail: '.$field_email."\n";     $body_message .= 'message: '.$field_message;     $headers = 'from: '.$field_email."\r\n";     $headers .= 'reply-to: '.$field_email."\r\n";     $mail_status = mail($mail_to, $subject, $body_message, $headers);      if ($mail_status) {         ?>          </script>     <?php      } else { ?>      <?php      }  ?> 

i dont know add inside if , else cases achieve objective? please me out..

you have use jquery's ajax function send form without refreshing page, here's official documentation: http://api.jquery.com/jquery.ajax/

hope helps!


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -