Skip to content Skip to sidebar Skip to footer

How To Display Php Form Validation Errors Beside The Form?

i have created a signup form which is validated by both javascript and php.Whenever any javascript form validation error occur such as username is required,it is displayed beside t

Solution 1:

Another option if you don't want to use ajax. It can be done with php but user need to reload the page to see error.

To do this, html form code and php validation code must be placed at the same file.

<?php 
    $error = false;
    if(isset($_POST['submit'])){                
        // your validation
            // if something wrong
            $error = true;  
    }
?>
<form action="validation_checking.php" method="post">
    <?php
        if($error)
        { echo '<p style="color:red;">Sorry, the username '.$_POST['username'].' is already in use.</p>'; } 
    ?>
    <input type="text" name="username"> 
    <input type="submit" value="submit">
</form>

Solution 2:

You must use ajax to execute php functions without refreshing the page. Read this


Post a Comment for "How To Display Php Form Validation Errors Beside The Form?"