PHP Server Side Form Validation | clear form after submit

Today, We want to share with you PHP Server Side Form Validation.In this post we will show you validation in php registration form, hear for serverside validation in php using jquery we will give you demo and example for implement.In this post, we will learn about Form validation client and serverside using PHP with clear form after submit php an example.

Server Side Form Validation

There are the Following The simple About PHP Server Side Form Validation Full Information With Example and source code.

As I will cover this Post with live Working example to develop php form validation and submit to database, so the serverside validation in php using ajax for this example is following below how to post multiple checkbox value in php.

Also Read This πŸ‘‰   Simple Laravel CRUD Validation Tutorial




  if($emp_name =="") {
    $errorMsg=  "error : You did not enter a name.";
    $code= "1" ;
  elseif($emp_number == "") {
    $errorMsg=  "error : Please enter number.";
    $code= "2";
  //check if the number field is numeric
  elseif(is_numeric(trim($emp_number)) == false){
    $errorMsg=  "error : Please enter numeric value.";
    $code= "2";
    $errorMsg=  "error : Number should be ten digits.";
    $code= "2";
  //check if email field is empty
  elseif($emp_email == ""){
    $errorMsg=  "error : You did not enter a email.";
    $code= "3";
} //check for valid email 
elseif(!preg_match("/^[_\.0-9a-zA-Z-][email protected]([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $emp_email)){
  $errorMsg= 'error : You did not enter a valid email.';
  $code= "3";
  echo "Success";
  //final code will execute here.


<!DOCTYPE html>
 <meta charset="utf-8">
 <title>Employee Information Sample HTML Form</title>
 <style type="text/css" >
  .errorMsg{border:1px solid red; }
  .message{color: red; font-weight:bold; }

  <?php if (isset($errorMsg)) { echo "<p class='message'>" .$errorMsg. "</p>" ;} ?>

<form name= "registration" id= "registration" method= "post" action= "">
<table width= "400" border= "0" align="center" cellpadding= "4" cellspacing= "1">
<td>Employee Name:</td>
<td><input name= "emp_name" type= "text" id="emp_name" value="<?php if(isset($name)){echo $name;} ?>"
<?php if(isset($code) && $code == 1){echo "class=errorMsg" ;} ?> ></td>
<td>Contact No.: </td>
<td><input name= "emp_number" type= "text" id= "emp_number" value="<?php if(isset($number)){echo $number;} ?>"
<?php if(isset($code) && $code == 2){echo "class=errorMsg" ;}?> ></td>
<td> Personal Email: </td>
<td><input name= "emp_email" type= "text" id= "emp_email" value="<?php if(isset($email)){echo $email; }?>"
<?php if(isset($code) && $code == 3){echo "class=errorMsg" ;}?> ></td>
<td><input type= "submit" name= "Submit" value= "Submit"></td>


Angular 6 CRUD Operations Application Tutorials

Read :

Also Read This πŸ‘‰   Get Current Plugin URL in WordPress


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about ServerSide Form Validation.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.