A simple but Secure Html form with validations using PHP

Here is another simple but Secure Html form with validations using PHP. All you need to do is just copy this code below, paste it in your Notepadd++ or whatever editor you are using and save that file. Now put that file in your htdocs folder in xampp and you are good to go.


<?php //php protion ?>


// Firstly I have defined the variables here and set them to empty values

$nam = $eml = $pass = "";
$namError = $emlError = $passError = "";


    $namError = "name is required";
    $nam = test_input($_POST["name"]);

    $emlError = "Email is required";
    $eml = test_input($_POST["email"]);

   if (empty($_POST["password"])) {
    $passError = "Password is required";
    $pass = test_input($_POST["password"]);

function test_input($data){
$data = trim($data);
$data = stripcslashes($data);
$data = htmlspecialchars($data);
return $data;


<?php //html portion ?>

<html lang="en">
<meta charset="UTF-8">
<title>Simple html form by TALHA SHOAIB</title>

<h1>A simple but Secure Html form with validations using PHP | developed by Talha shoaib, available at <a href="https://techkwave.blogspot.com/">Tech wave</a></h1>

        <span style="color: red;">* Required feilds</span>
        <form action=" <?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ?> " method="post">
            <input type="text" name="name" placeholder="Enter your name">
            <span style="color: red;">* <?php echo $namError; ?> </span>
            <input type="email" name="email" placeholder="Enter your email">
            <span style="color: red;">* <?php echo $emlError; ?> </span>
            <input type="password" name="password" placeholder="Password">
            <span style="color: red;">* <?php echo $passError; ?> </span>
            <input type="submit" name="btn" value="Button">

          echo "<h1>Output:</h1><br><br>";

          echo "Your name: $nam <br>";
          echo "Your Email: $eml <br>";
          echo "Your Password: $pass";

if you are facing any problem, then let me know in the comment section and let’s solve it together.

Result screen

Share it in your network:

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.



You have successfully subscribed to my email list. Now you will be recieving latest wordpress tips and tricks directly in your mail box.

Don’t worry! I won’t spam you