开发者

(Jquery Validate Plugin) How can be 1 of the form fields validate with ajax call and the rest fields with client validation?

How can be 1 of the form fields validate with ajax call and the rest fields with client validation? (I use Jquery + Jquery validate plugin http://bassistance.de/jquery-plugins/jquery-plugin-validation/)

The case:

register.html

<form id="register" name="register">
firstname<input id="username" name="username"/>
user<input id="user" name="user"/>
phone<input id="phone" name="phone"/>
</form>

<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../jquery.validate.js" type="text/javascript"></script>
$('#register').validate(
{
rules: {
        firstname: "required",
        phone: "required开发者_StackOverflow社区"
  }
});

user_exist.php:

if ( userExist($_REQUEST['user']){
  echo 'success';
}
else{
  echo 'please choose another user'
}

I know how validate only firstname and phone, but username that should be validate by server before submit I don't.

Please help me to do serveer ajax validation for user field. (I simplify the code) Thanks


there's an exact example in the demo pages:
http://jquery.bassistance.de/validate/demo/milk/

username: {
    required: true,
    minlength: 2,
    remote: "users.php"
},

Just remember to echo "true"; on success in your server side

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜