Black Friday Sale! Get up to $30 off GP Premium! Learn more ➝

[Resolved] Preventing double click on rego form (adding jquery to functions file)

Home Forums Support [Resolved] Preventing double click on rego form (adding jquery to functions file)

Home Forums Support Preventing double click on rego form (adding jquery to functions file)

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #217371
    Max

    Hey Tom

    I have a redirect on registration to a welcome page. It takes a while for the redirect to happen.

    If a user double clicks on the register button prior to the redirect, the redirect doesn’t happen and you get the follow error message on the form:

    ERROR: This username is already registered. Please choose another one.
    ERROR: This email is already registered, please choose another one.

    The problem is that the user does not receive any notice that he has received the email to create his password…and so is just left hanging

    I found this thread on stack overflow that seem to have a solution:

    http://stackoverflow.com/questions/2323948/disabling-the-button-after-once-click

    I tried inserting the following into my functionality plugin. It appears to work regarding the single click. But then it adds scipt to the bottom of all my pages:

    add_action( 'wp_footer','max_oneclick_code' );
    function max_oneclick_code()
    {
        ?>
        jQuery( document ).ready( function($) {
        $('#wp-submit').one('submit', function() {
        $(this).find('input[type="submit"]').attr('disabled','disabled');
        });
        });
        <?php
    }

    What is the best way to limit rego form submit button click to one time only. Is the snippet provided on Stack Overflow any good?

    And what is the best way to intergrate it into your GP theme.

    Can I use a hook? Or is it possible to edit one of your theme file in my child theme?

    As always, thanks in advance for any assistance you can offer.

    Kind REgards

    Max

    #217372
    Max
    #217446
    Tom
    Lead Developer
    Lead Developer

    Hi Max,

    That snippet isn’t bad at all – no issue with it loading on every page πŸ™‚

    #217453
    Max

    Not sure if you are being sarcastic πŸ™‚

    The script actually appears written across the bottom of each of my pages…

    I am in way over my head here…

    #217457
    Tom
    Lead Developer
    Lead Developer

    Ah I see, you need to wrap the content in <script> tags.

    So it would be:

    <script>
    jQuery in here
    </script>
    #217458
    Max

    So does this look right?:

    add_action( 'wp_footer','max_oneclick_code' );
    function max_oneclick_code()
    {
        ?>
        <script>
        jQuery( document ).ready( function($) {
        $('#wp-submit').one('submit', function() {
        $(this).find('input[type="submit"]').attr('disabled','disabled');
        });
        });
        </script>
        <?php
    }
    #217459
    Max

    When I logged in to this thread I also noticed that you are using a function to have me arrive back at the same page that I was on prior to login.

    I have spent many hours looking for that snippet.

    Any chance you can share yours?

    Thanks as always.

    Kind Regards

    Max

    #217516
    Tom
    Lead Developer
    Lead Developer
    #217523
    Max

    Hey Tom

    Your last link regarding a logging in goes to a cart sales screen. Is that what you wanted me to see?

    Or is the link wrong?

    Kind Regards

    Max

    #217526
    Tom
    Lead Developer
    Lead Developer

    Ha, sorry about that – check it out now πŸ™‚

    #217529
    Max

    So I am currently using this snippet to redirect both admin and users on login:

    //LOGIN REDIRECT ADMIN TO ADMIN AND USERS TO FORUMS
    function my_login_redirect($redirect_to, $request, $user){
    return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : home_url('/forums/');
    } 

    And then I see from the link you posted that this is the relevant code to redirect back to orginal page:

    <a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">Login</a>

    But I can’t see how to bolt these two together….

    #217530
    Max

    My log in out code is as follows:

    //MY LOGIN SHORTCODE [my_login]
    add_shortcode( 'my_login', 'my_login' );
    function my_login() {
    	if ( ! is_user_logged_in() )
    		return '<a class="button login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">LOG IN</a>';
    	else
    		return '<a class="button login" href="' . esc_url( wp_logout_url( get_permalink() ) ) . '">LOG OUT</a>';
    }
    //END MY LOGIN SHORTCODE

    However it doesn’t work perfectly like your login logout button here at GP

    What have I got wrong?

    Kind REgards

    Max

    #217542
    Tom
    Lead Developer
    Lead Developer

    Can’t see anything obvious I’m afraid.

    General WP questions like this are better suited for http://wordpress.stackexchange.com

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.