简体   繁体   English

FaceBook注册插件异步验证表单(以检查用户名是否可用)

[英]FaceBook Registration Plugin Async Validate form (to check Username availbility)

Ok, So I have Google the hell out of this problem and the FB Advanced Registration documentation also did not help. 好的,所以我让Google摆脱了这个问题, FB高级注册文档也没有帮助。 I want to have a Facebook Registration where a user can choose(& Check availability of) his username like this: 我想要一个Facebook注册,用户可以在其中选择(和检查其)用户名,如下所示:
(Screenshot of what I plan to do but have failed to do, since I cant post picturesin this question directly) A link to Screenshot of what I wanted ! (由于我无法直接在此问题中发布图片,因此我打算做的屏幕截图,但没有完成) 。指向我想要的屏幕截图的链接

I plan to check the availability of the username from my DB in mysql using PHP, but I am stuck with this weird JSON callback thing which I have failed to understand. 我计划使用PHP在mysql中从我的数据库中检查用户名的可用性,但是我仍然无法理解这个奇怪的JSON回调。 My Registration Plugin looks something like this 我的注册插件看起来像这样

<fb:registration 
fields='[{"name":"name"},{"name":"username","description":"Username","type":"text"}]' 
onvalidate="validate_async"    
redirect-uri="http://mysite.com/loginFB.php"
fb_only="false"
width="530">

</fb:registration>    

 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
 <script> 
 function validate_async(form, cb) {
 // $.getJSON('https://graph.facebook.com/' + form.username + '?callback=?',//CODE obtained from FB documentation 
    $.getJSON('https://mysite.com/checkUsername.php?username=' + form.username + '?callback=?',
        function(response) {
          if (response.error== "false") {
        // Username isn't taken, let the form submit
        cb();
      }
      cb({username: 'That username is taken, Sorry!'});
  });
}
 </script> 

I wanted to know WHAT EXACTLY do I write the in the checkUsername.php . 我想知道我该怎么写在checkUsername.php中
Right now I have come up with the following code for checkUsername.php which does NOT work: 现在,我为checkUsername.php提出了以下代码,该代码不起作用:

 <?php 
 $conn = dbconnect(GLOBAL_Db);
$username = $_GET['username'];
$data = array();
$table = mysql_real_escape_string(GLOBAL_Db. "." . GLOBAL_Users);
 $sqlCommand = "SELECT * FROM ".$table." WHERE username='$username'";
 $query = mysql_query($sqlCommand) or die (mysql_error());
 $num_rows = mysql_num_rows($query);

if($num_rows>0){
    $data['error'] = "true";
} else {
$data['error'] = "false";
}
echo json_encode($data);
?>   

This code does not give me that that "The username is taken, Sorry" Message , WHY??? 此代码不会告诉我“用户名已使用,抱歉”消息,为什么?
I would really appreciate it if anyone could actually help me out with this getJSON function in the script , AND Also help me out with the checkUsername.php since I have a very crude knowledge of JSON, (JSONP) etc. ! 如果有人可以在脚本中真正帮助我解决此getJSON函数,我将非常感激,并且由于我对JSON,(JSONP)等非常了解,还可以通过checkUsername.php帮助我! Would be glad to put in more effort to explaain my problem coz this is bugging me for like a Week now! 很高兴付出更多的努力来解释我的问题,因为这使我烦恼了一个星期! Happy to accept some valuable help from you guys! 很高兴接受你们的一些宝贵帮助!

$username = $_GET('username');

$_GET is not a function … maybe you should familiarize yourself with some PHP basics first? $ _GET不是函数…也许您应该首先熟悉一些PHP基础知识?

Besides that, your script logic looks a bit weird … 除此之外,您的脚本逻辑看起来有些奇怪……

if($num_rows>0){
    $data['error'] = "true";
} else {

    $data['username'] = $row['username'];
}

If now rows are found, then you want to access the username field in a row that's not there ? 如果现在找到行,那么您要访问不存在的行中的用户名字段?

(And you're not even quoting the username you get as a GET parameter, OMG …) (而且您甚至都没有引用作为GET参数获得的用户名OMG…)


Set error to true or false depending on if there are rows or none. 根据是否存在行将错误设置为true或false。

And then, in your JS function, give the „username is taken”-message if error=true. 然后,在您的JS函数中,如果error = true,则输入“采用用户名”消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM