WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: Simple Facebook Connect] Comments - Not working with Javascript validation (11 posts)

  1. saharusa
    Member
    Posted 4 years ago #

    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 ?

    http://wordpress.org/extend/plugins/simple-facebook-connect/

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 4 years ago #

    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.

  3. saharusa
    Member
    Posted 4 years ago #

    Thanks

  4. Joe
    Member
    Posted 3 years ago #

    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.

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 3 years ago #

    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.

  6. Joe
    Member
    Posted 3 years ago #

    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.

  7. Samuel Wood (Otto)
    Tech Ninja
    Posted 3 years ago #

    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
    }

  8. Joe
    Member
    Posted 3 years ago #

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

    jQuery(document).ready(function($) {
    
    $('.multi-sidebar').tabs();
    
    <?php if (!function_exists('pixopoint_menu')) : ?>
    $('.sf-menu').superfish({autoArrows: true, speed: 'fast', dropShadows: 'true'});
    <?php endif ?>
    
    <?php if (is_singular()) : ?>
    
    $('#commentform').validate()
    
    <?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.

  9. Samuel Wood (Otto)
    Tech Ninja
    Posted 3 years ago #

    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.

  10. Joe
    Member
    Posted 3 years ago #

    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.

  11. Samuel Wood (Otto)
    Tech Ninja
    Posted 3 years ago #

    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 () {
    	FB.Connect.ifUserConnected(sfc_update_user_details);

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic