The correct way to validate a form with php (or maybe something else, aka AJAX)

How it's done. Now let me delve into more detail. I want to make a professional, or at least professional, seemingly validation method for all my forms, from now on with my career. I heard a lot about using AJAX to correctly check some fields before the user even left the page, this interests me.

Here is my sample form;

<form action="<?=$frontend['url']?>php/php-login-submission.php" method="post" id="loginForm">
    <table width="300px" border="0px" cellpadding="5">
    <tr>
        <td><label><b>Email:</b></label></td>
        <td align="right"><input name="email" type="text" id="email" placeholder="registered@email.co.uk" tabindex="1" title="email" size="30" /></td>
    </tr>
    <tr>
        <td><label><b>Password:</b></label></td>
        <td align="right"><input name="password" type="password" id="password" placeholder="********" tabindex="2" title="password" size="30" /></td>
    </tr>
    <tr>
        <td></td>
        <td align="right"><input type="submit" id="loginBtn" value="Login" /></td>
    </tr>
    </table>
</form>

Using AJAX and php, how can I validate this form correctly. I am not opposed to sending data to an intermediate page, for example php/php-login-submission.php, to then redirect them to pages/members-area.phpif they pass validation.

So far I have used methods such as:

if (!isset($_POST['email']))    $_SESSION['errortext'] = 'You must provide an email.';

$_SESSION['errortext'] . .

AJAX, Javascript.

, , - , , , . ,

.

+3
1

, , jQuery jQuery , , , , , , . , , ""

+1

All Articles