Archived topic
Preventing double click on rego form (adding jquery to functions file)
12 replies · Started by Max on August 11, 2016
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
Found this but for gravity form not wp rego form:
https://snippets.webaware.com.au/snippets/stop-users-from-submitting-gravity-forms-form-twice/
Hi Max,
That snippet isn't bad at all - no issue with it loading on every page :)
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...
Ah I see, you need to wrap the content in <script> tags.
So it would be:
<script>
jQuery in here
</script>
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
}
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
That looks good.
As for logging in, check out this function: https://codex.wordpress.org/Function_Reference/wp_login_url
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
Ha, sorry about that - check it out now :)
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....
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
Can't see anything obvious I'm afraid.
General WP questions like this are better suited for http://wordpress.stackexchange.com