10

I'm trying to implement Facebook registration on a website. Without the onvalidate parameter, everything works as one would expect it to, but when including it everything seems to break down (no errors thrown, form does nothing).

Here is my code:

<center>
    <fb:registration redirect-uri="http://im.localhost/register"
    fields='[{"name":"name"},{"name":"username","description":"Website Username","type":"text"},{"name":"email"},{"name":"password","view":"not_prefilled"},{"name":"captcha","view":"not_prefilled"},{"name":"tos","type":"checkbox","description":"I accept the Terms of Service"}]' onvalidate='validate'>
    </fb:registration>
</center>
<script> 
function validate(form) {
    console.log('Validation');
    errors = {};
    errors.tos = "You must accept the terms of service";
    return errors;
}
</script>
<!-- at end of page: -->
<script>
    // ...
    FB.init({
        appId: '<?php echo IM_Facebook::getAppIDStatically(); ?>',
        channelUrl: '<?php echo $this->serverUrl().$this->baseUrl('/xsrd.html'); ?>',
        status: true,
        cookie: true,
        xfbml: true
    });
    // ...
</script>

The console.log function is never called on hitting the form's submit button. (However, otherwise it acts almost normal - the pop up "You have registered using abc" shows up and disappears when I click confirm - but nothing else happens.

If I leave the custom field (username) blank without this parameter, Facebook asks me to fill it. If I leave it blank with this parameter, the validate function isn't called and it doesn't show any error. Either way, the TOS error that should always show up according to this form never shows up.

Similar questions' problems involve the website URL not matching that of the application. That is not the case, in this instance.

For domain clarification, I'm using the domain "im.localhost" which is inaccessible via the internet. I do not believe this is a problem, because without the onvalidate the registration form works, and the login system I've implemented work. With onvalidate, however, the registration form ceases to work at all.

Navarr
  • 3,703
  • 7
  • 33
  • 57
  • not really familiar with this stuff, but are you sure the correct syntax is not `onvalidate="validate()"` – Zach Lysobey Feb 13 '13 at 22:31
  • @ZachL Doing it as you've described results in: "Unable to load the registration form for %appname (self-filtered)%. You may have previously blocked this app on Facebook. Go to your Facebook privacy settings to unblock this app. (Error: Just pass the javascript function name in 'onvalidate', don't put ().)" – Navarr Feb 13 '13 at 22:32
  • Also, perhaps it will help if you show the generated source... – Zach Lysobey Feb 13 '13 at 22:43
  • If you substitute the [example code from the facebook docs](https://developers.facebook.com/docs/plugins/registration/advanced/) does it work as expected? I've been reading the docs, and staring at your code, and there don't appear to be any errors... – Zach Lysobey Feb 13 '13 at 23:08
  • @Navarr, can you see anything on the JS console in Chrome or Firefox? Also, there's a bug filed at FB precisely for this: https://developers.facebook.com/bugs/317808814971472 – Leo supports Monica Cellio Feb 19 '13 at 21:55
  • @NannuoLei We moved away from this form for various reasons at the company I'm working; however there were no console errors. validate was never being called. In fact the whole form stopped working with no errors when the validate attribute was set. – Navarr Feb 20 '13 at 01:29

1 Answers1

1
  onvalidate="validate()"

onvalidate="validate" you are just calling a string...

you need the parenthesis to call a function

Dnaso
  • 1,335
  • 4
  • 22
  • 48
  • Please refer to the comment thread under the original question. Though this is nearly a year old. http://stackoverflow.com/questions/14819455/fbregistration-onvalidate-not-working/20308282?iemail=1&noredirect=1#comment20837792_14819455 – Navarr Dec 01 '13 at 16:29