开发者

how is this jquery app validating the username? (3rd party script)

开发者 https://www.devze.com 2022-12-19 10:24 出处:网络
The tutorial that I\'m trying to figure out is this: http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/

The tutorial that I'm trying to figure out is this:

http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/

The username field looks like this:

<input value="" class="validate[required,custom[noSpecialCaracters],length[0,20],ajax[ajaxUser]]" type="text" name="user" id="user" />

That <input> field has a class item named ajax[ajaxUser] which has its rules contained in开发者_JS百科 this script (jquery.validationEngine-en.js).

The snippet for that item looks like this:

"ajaxUser":{
    "file":"validateUser.php",
    "extraData":"name=eric",
    "alertTextOk":"* This user is available",   
    "alertTextLoad":"* Loading, please wait",
    "alertText":"* This user is already taken"},

What I can't figure out at all is how its PHP page is working which is validateUser.php. Where are all those post fields coming from? I looked around and can't find a field with those names.

Thanks


The php page (or any engine/framework you would like to use) takes the following post variables:

  • email ced@hotmail.com
  • firstname2 karnius
  • lastname2 karnius
  • name anything
  • user2 karnius

And returns either true or false as the entire response. The messages defined in your question are displayed depending on which response it gets.


The post data looks like this:

validateValue=karnius&validateId=user&validateError=ajaxUser

It appears that validateId is the form element name and validateError comes from ajax[ajaxUser].

The response looks like this:

{"jsonValidateReturn":["user","ajaxUser","true"]}

The PHP code could look something like this:

<?php
    $result = mysql_query('SELECT 1 FROM users WHERE username = "'.mysql_real_escape_string($_POST['validateValue']).'"');
    $response = $result ? 'false' : 'true';
    echo json_encode(array('jsonValidateReturn' => array(
        $_POST['validateId'],
        $_POST['validateError'],
        $response)));
?>

(Obviously, a more complicated handler could base its behavior on validateId and validateError.)

0

精彩评论

暂无评论...
验证码 换一张
取 消