PHP Ajax Form Validation without page refresh

PHP Ajax Form Validation without page refresh

In this Post We Will Explain About is PHP Ajax Form Validation without page refresh With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to submit form using ajax without page refresh Example

In this post we will show you Best way to implement ajax contact form with validation, hear for php form validation example code download with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Simple PHP Ajax Form Validation Example from scratch

Here, We will make PHP simple contact us form submit using html with php ajax source code bootstrap framework. When We simple click on “Send Comments” button it will simple call php file fire ajax post jquery send request and check check some validation and show display it as now on simple bellow source code preview. We will make two simple file following files for index.php, and do_submit.php and include scripts this example:

Also Read This πŸ‘‰   PHP Laravel 6 DataTables Tutorial


<!DOCTYPE html>
	<title> Php Ajax Form simple Validation Example</title>
	<script type="text/javascript" src=""></script>
	<script type="text/javascript" src="script.js"></script>
  <link rel="stylesheet" href="">

<div class="container">
  <h1>Step By Step Php Ajax Form simple Validation Example</h1>
  <form role="form" id="contactForm" class="contact-form" data-toggle="validator" class="shake">
    <div class="alert alert-danger display-live-error" style="display: none">
    <div class="form-group">
      <div class="controls">
        <input type="text" id="name" class="form-control" placeholder="Enter your Name">
    <div class="form-group">
      <div class="controls">
        <input type="email" class="email form-control" id="email" placeholder="Enter your Email" >
    <div class="form-group">
      <div class="controls">
        <input type="text" id="mail_sub" class="form-control" placeholder="Enter your Subject" >
    <div class="form-group">
      <div class="controls">
        <textarea id="comments" rows="7" placeholder="Enter your Massage" class="form-control"></textarea>
    <button type="submit" id="submit" class="btn btn-success"><i class="fa fa-check"></i> Send Comments</button>


<script type="text/javascript">
  $(document).ready(function() {
	//form submit live

        var name = $("#name").val();
        var email = $("#email").val();
        var mail_sub = $("#mail_sub").val();
        var comments = $("#comments").val();

            type: "POST",
            url: "/do_submit.php",
            dataType: "json",
            data: {name:name, email:email, mail_sub:mail_sub, comments:comments},
            success : function(data){
                if (data.code == "200"){
                    alert("Success: " +data.msg);
                } else {




$live_comments_error = "";

/* Devloped by NAME */
if (empty($_POST["name"])) {
    $live_comments_error = "<li>Your Name is required</<li>";
} else {
    $name = $_POST["name"];

/* Devloped by EMAIL */
if (empty($_POST["email"])) {
    $live_comments_error .= "<li>Your Email is required</li>";
} else if(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
    $live_comments_error .= "<li>Invalid email format</li>";
}else {
    $email = $_POST["email"];

/*Devloped by MSG SUBJECT */
if (empty($_POST["mail_sub"])) {
    $live_comments_error .= "<li>Your Subject is required</li>";
} else {
    $mail_sub = $_POST["mail_sub"];

/*Devloped by MESSAGE */
if (empty($_POST["comments"])) {
    $live_comments_error .= "<li>Your Comments is required</li>";
} else {
    $comments = $_POST["comments"];

	$msg = "Your Name: ".$name.", Your Email: ".$email.", Your Subject: ".$mail_sub.", Your Comments:".$comments;
	echo json_encode(['code'=>200, 'msg'=>$msg]);
//return form message 
echo json_encode(['code'=>404, 'msg'=>$live_comments_error]);


You are Most welcome in my youtube Channel Please shubscibe my channel. and give me FeedBack.
More Details……
Angularjs Example

Also Read This πŸ‘‰   jQuery AJAX Submit form serialize PHP MySQLi


I hope you have Got What is Simple PHP Ajax Form Validation Example from scratch And how it works.I would Like to have FeedBack From My Blog( readers.Your Valuable FeedBack,Any Question,or any Comments about This Article( Are Most Always Welcome.