douyun8674 2012-10-08 23:54
浏览 53

JQuery.Validate() - 远程规则

I'm developing a Web site for a school project. Though I mainly work with PHP, I thoght I should as well do some client-side validation. It took a very short search in Google to find the Validate JQuery plugin. And so far this is what I've got:

<form id="regform" class="well" method="post" action="Registering.php">
        <label>Name: <input type="text" placeholder="Type your name" name="Name" class="required" /></label>
        <label>Surname: <input type="text" placeholder="Type your surname" name="Surname" class="required" /></label>
        <label>Username: <input type="text" placeholder="Type your username" name="Username" class="required" /></label>
        <label>Password: <input type="password" placeholder="Type your password" name="Password" class="required" /></label>
        <label>Repeat Password: <input type="password" placeholder="Confirm Password" name="Password-confirm" class="required" /></label>
        <label>E-Mail: <input type="Email" placeholder="Type your Email" name="Email" class="required email" /></label>
        <label>Birthday: <input type="Date" name="Birthday" /></label>
        <label>Gender:</label>
        <label>Male <input type="radio" name="Gender" value="0" checked> Female <input type="radio" name="Gender" value="1"></label>
        <label>Photo: <input type="url" placeholder="Paste an image link" name="PhotoLink" class="url" /></label>
        <label><input type="submit" class="btn btn-primary" name="Submit" value="Register in YouTune" /></label>
 </form>

This is the form, pretty much a standard registration one. Nothing to add here. And then I have this small Javascript:

$(document).ready(function(){
        $("#regform").validate({
            rules: {
                Username: {
                    remote: { url: "/check_username.php", async: false }
                }
            },
            messages: {
                Username: { remote: "Username already on use. Pick a different one." }
            }
        });
});

Both scripts of the lastest JQuery library and the version 1.10 of the Validate Plugin were added on the head of the document.

Well, to make it short, the validation stuff runs smooth, except that the remote rule is not working. It is as if it wasn't there at all, no error message whether I submit with an already used Username or not. The php file that the Javascript is calling has the following script:

<?php error_reporting(E_ALL);
     require_once("../Clases/User.php");
     header('Content-type: application/json');
     $vUser = new User();
     $vResult = $vUser->GetUserByUsername($_REQUEST["Username"]);
     if ($vResult) {
    echo false;
     } else { echo true; }

?>

The GetUserByUsername method goes to a DataBase and searches for a User with the given parameter, then returns true if there was a match up, false if there wasn't. I've tested it without the remote call from the Javascript and it works fine

So, does anyone know why is this happening?

Thank you beforehand for taking the time read and trying to help me with this small issue.

EDIT: Solved. I just had to fix the source for the remote call. Can't believe I missed that. Anyway, thank you very much for the help.

  • 写回答

1条回答 默认 最新

  • doushi2047 2012-10-09 14:02
    关注

    I am not very sure but see if it works; remove "/" from your url. use "check_username.php" in place of "/check_username.php" or absolute url

    评论

报告相同问题?

悬赏问题

  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置