Support » Plugins » [Plugin: Simple Facebook Connect] Comments – Not working with Javascript validation

  • Resolved Sahar


    Hi there,
    Usually I add js validation to wp comments form (don’t like the white and empty wp php error page)

    Validation script check if something entered for required fields, which working just fine for normal commenting, but when i login using simple-facebook-connect, i can’t send the form, validation will never pass because the required fields are now hidden but still empty…

    Is there any way to populate required fields after facebook login ?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    No, the plugin adds the data after the form is submitted, on the back end. Basically it fills in those fields before WordPress sees them.

    So you need to change your validation function. Have the code check for the “fb_connect_user” variable. If it’s true, then the user logged into Facebook.


    So, did anyone ever figure out a way to use the javascript validation along with the Simple Facebook Connect plugin?

    Saharusa, did you accomplish this?

    I’ve tried and tried, but my javascript is just crap, and I can’t manage. It would be nice to be able to use Facebook for some comments and still be able to use jquery’s validate function for the others. Otherwise, people have to retype their entire comment if they forget to enter a username or password.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Essentially, you don’t use javascript validation. The SFC-Comments bit happens on the back end, so those fields won’t be filled in when submitting the comment.

    Turn off the JS validation.

    Yeah, I get that Otto 😉

    My point was- it might be nice to be able to use SFC Comments AND the JS validation as well 🙂

    I’ve been trying to do it through some javascript calls to turn validation on when fb_connect_user = false, and turn it off when fb_connect_user = true, but it’s just not working.

    I’m now considering trying a different route: setting a cookie for the fb_connect_user value and then using that to switch on and off validation. Not sure when I’ll get a chance to give it a proper go though, as I have a ton of other stuff on my blog that needs to be fixed first.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Without knowing your validation JS code, I can’t tell you how to do it.

    It should be as simple as wrapping the validation code in an if statement, really.

    if (!fb_connect_user) {
    … validation code here

    I’m using the jquery validate function in the arras theme:

    jQuery(document).ready(function($) {
    <?php if (!function_exists('pixopoint_menu')) : ?>
    $('.sf-menu').superfish({autoArrows: true, speed: 'fast', dropShadows: 'true'});
    <?php endif ?>
    <?php if (is_singular()) : ?>
    <?php endif ?>
    <?php do_action('arras_custom_scripts') ?>

    in the head of the page.

    The problem I’m finding is that when I check the fb_connect_user value, it only shows up when I place the check below the footer(ie below the SFC comments code.

    Also the fb_connect_user variable always returns “false”, even when I’m logged in via Facebook.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    The fb_connect_user is a pagewide var, but it won’t get set to true until after the user actually logged in. So you need to adjust your validation to happen after that. The code you posted above is hooking in the validation before any of that code runs.

    Thanks for the help Otto. The part that is really confusing me is that the fb_connect_user variable never seems to get set to “true”, even when I am logged in.

    I put document.write(fb_connect_user); in the footer of the page just above the </body> tag. The value is always “false”, whether I’m logged in via Facebook or not.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    The value will remain false until you log in, and that happens later in time than when you’re running the document.write.

    See, you don’t start out logged in, even on a new page load. The log in to Facebook happens after the page loads.

    Basically, the sfc_update_user_details function is what sets that to true. And sfc_update_user_details gets called by this code:

    FB.ensureInit ( function () {

    That delays the starting of the code until a) The FB connect code loads and initializes and then b) the FB connect code checks to see if you’re connected to the site via your FB credentials. Only then does the code get run and the variable set to true.

    Basically, you’re running your validation code way before the FB code ever runs. Doesn’t matter where on the page you put it, Javascript is an event driven language. Your code is running before the event that causes the FB credentials to be checked.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: Simple Facebook Connect] Comments – Not working with Javascript validation’ is closed to new replies.