1
我使用嵌入HTML5文档的XFBML。我已经按照Facebook网站上的“注册高级使用”文档中提供的说明设置了客户端验证,但它仅在模糊时显示错误,并且在单击“注册”按钮时不会验证(所以如果我填写一个字段错误,并在另一个元素上点击外部,它会显示错误,但我可以点击注册按钮,并且它会注册我)。使用Facebook注册的客户端验证XFBML
我已经在JS调试器中追踪了它,并添加了警报/日志语句,而我的validate_registration
函数仅被称为onblur,并且从未单击Register按钮。
任何人看到这种行为,并知道我在这里失踪? Facebook上的“注册高级使用”的实例可以完美地工作,所以我知道我在某个地方犯了一个错误。
我XFBML标签是这样的:
<div class="fb-registration"
onvalidate="validate_registration"
fields="[
{'name': 'name'},
{'name': 'first_name'},
{'name': 'gender'},
{'name': 'email'},
{'name': 'user_type', 'description': 'Are you a?', 'type': 'select',
'options': {
'parent': 'Parent/Guardian looking for childcare',
'sitter': 'Babysitter/Nanny looking for sitting jobs'
}
},
{'name': 'zip_code', 'description': 'Zip code', 'type': 'text'},
{'name': 'over_eighteen', 'description': 'I am at least 18 years old', 'type': 'checkbox' }
]"
fb_only="true"
redirect-uri="<%= parse_fb_connect_signed_request_users_url %>"
width="530">
</div>
和我的验证功能是这样的:
function validate_registration (custom_fields) {
var errors = {},
regexZipCode = /^\d\d\d\d\d$/;
console.log("in validate_registration");
if (custom_fields.user_type !== 'parent' && custom_fields.user_type !== 'sitter') {
errors.user_type = "Select either Parent or Sitter";
}
if (! regexZipCode.test(custom_fields.zip_code)) {
errors.zip_code = 'Enter your 5-digit U.S. zip code';
}
if (! custom_fields.over_eighteen) {
errors.over_eighteen = 'You must be at least 18 years old to use this site!';
}
return errors;
}
是的,有趣的如何在Facebook发言“你刚刚注册”并不意味着“你刚刚注册”。我今天花了几个小时试图解决这个问题,并在放弃之前看到你的帖子。谢谢! – danorton 2012-03-03 04:33:06