Captcha for registration form
This topic contains 30 replies, has 8 voices, and was last updated by Paolo 9 years, 10 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: captcha, registration form
-
AuthorPosts
-
July 30, 2014 at 12:50 am #10313
Hi,
Is there a captcha form available that will work on the registration page. We only get one or two a day but as we grow I would like to not have that become
a larger concern.Thanks,
July 30, 2014 at 10:40 am #10339July 30, 2014 at 6:49 pm #10421Hi,
quick tutorial to use this plugin in your register form:
https://wordpress.org/plugins/simple-recaptcha/
1st of all install the plugin, get your reCaptcha API public and private keys here: https://www.google.com/recaptcha/admin#whyrecaptcha and add them to the plugin settings.
Copy file plugins/geodirectory/geodirectory-templates/reg_frm.php and paste it into themes/your-child-theme/geodirectory/reg_frm.php
Open the file and add the code below inside the
tags, above or below the registration button and save.
<?php // is Simple reCAPTCHA active? if ( function_exists( 'wpmsrc_display' ) ) { echo wpmsrc_display(); } ?>
Now open your child theme functions.php and add the reCaptcha validation code:
<?php // is Simple reCAPTCHA active? if ( function_exists( 'wpmsrc_check' ) ) { // check for empty user response first (optional) if ( empty( $_POST['recaptcha_response_field'] ) ) { $errors['captcha'] = __( 'Please complete the CAPTCHA.', 'yourtextdomain' ); } else { // check captcha $response = wpmsrc_check(); if ( ! $response->is_valid ) { $errors['captcha'] = __( 'The CAPTCHA was not entered correctly. Please try again.', 'yourtextdomain' ); // $response['error'] contains the actual error message, e.g. "incorrect-captcha-sol" } } } ?>
And remove the original login and register form with the following remove action call:
remove_action( 'geodir_signup_forms', 'geodir_action_signup_forms', 10 );
Open geodirectory/geodirectory_template_actions.php and find function geodir_action_signup_forms, copy it and paste it in your child theme functions.php
file. Make sure to rename it to something like my_geodir_action_signup_forms before saving.Modify the function to make the plugin use the reg_frm.php from your child theme:
change this :
<?php include (geodir_plugin_path() . "/geodirectory-templates/reg_frm.php"); ?>
with this:
<?php include (get_stylesheet_directory() . "/geodirectory/reg_frm.php"); ?>
There are 2 of them.
In your child theme it should look like this:
function my_geodir_action_signup_forms(){ ?> <script type="text/javascript" > <?php if ( $user_login ) { ?> setTimeout( function(){ try{ d = document.getElementById('user_pass'); d.value = ''; d.focus(); } catch(e){} }, 200); <?php } else { ?> try{document.getElementById('user_login').focus();}catch(e){} <?php } ?> </script> <script type="text/javascript" > <?php if ( $user_login ) { ?> setTimeout( function(){ try{ d = document.getElementById('user_pass'); d.value = ''; d.focus(); } catch(e){} }, 200); <?php } else { ?> try{document.getElementById('user_login').focus();}catch(e){} <?php } ?> </script><?php global $errors; if(isset($_REQUEST['msg']) && $_REQUEST['msg']=='claim') $errors->add('claim_login', LOGIN_CLAIM); if(!empty($errors)){ foreach($errors as $errorsObj) { foreach($errorsObj as $key=>$val) { for($i=0;$i<count($val);$i++) { echo "<div class=sucess_msg>".$val[$i].'</div>'; $registration_error_msg = 1; } } } } if(isset($_REQUEST['page']) && $_REQUEST['page']=='login' && isset($_REQUEST['page1']) && $_REQUEST['page1']=='sign_in'){?> <div class="login_form"> <?php include (geodir_plugin_path() . "/geodirectory-templates/login_frm.php"); ?> </div> <?php }elseif(isset($_REQUEST['page']) && $_REQUEST['page']=='login' && isset($_REQUEST['page1']) && $_REQUEST['page1']=='sign_up'){ ?> <div class="registration_form"> <?php include (get_stylesheet_directory() . "/geodirectory/reg_frm.php"); ?> </div> <?php }else { ?> <div class="login_form_l"> <?php include (geodir_plugin_path() . "/geodirectory-templates/login_frm.php");?> </div> <div class="registration_form_r"> <?php include (get_stylesheet_directory() . "/geodirectory/reg_frm.php"); ?> </div> <?php }?> <script type="text/javascript"> try{document.getElementById('user_login').focus();}catch(e){} </script> <?php if((isset($errors->errors['invalidcombo']) && $errors->errors['invalidcombo'] != '') || (isset($errors->errors['empty_username']) && $errors->errors['empty_username'] != '')) {?> <script type="text/javascript">document.getElementById('lostpassword_form').style.display = '';</script> <?php } }
In your functions.php file add the new action:
add_action( 'geodir_signup_forms', 'my_geodir_action_signup_forms', 10 );
Given that the form is too narrow to accomodate the reCaptcha form, add this to your child theme style.css
.registration_form_r { width: 35%; }
This is tested and works, the only problem I’ve seen is the reCaptcha form is not perfectly styled, but the plugin is fairly new and Iìve asked the developer to look into it.
Thx
July 30, 2014 at 7:42 pm #10431to fix the reCaptcha styling issue add to your child theme style.css
#recaptcha_response_field { display: inline; height: 20px; }
Thx
July 30, 2014 at 9:05 pm #10448Is that all? and I thought it might be involved.
Thanks, I’ll give it a try.
My Math Captcha works great on the login profile, just not the registration.
July 30, 2014 at 9:09 pm #10450Looks longer than it really is… It took me 2 minutes to do it and 5 to write the tutorial 🙂
July 30, 2014 at 9:45 pm #10453I hit a snag,
I don’t see a geodirectory folder in my child theme.
I only have the files below:
.ds_store
favicon.ico
functions.php
header.php
screenshot.png
style.cssJuly 30, 2014 at 10:04 pm #10456Hi Nasc,
that’s normal, you need to create it via FTP client before moving copied file in it.
Thx
July 31, 2014 at 12:14 am #10472Thought I had it licked, Apparently not. My site no longer loads.
I will see If I can’t put it back to square one.
July 31, 2014 at 4:20 pm #10536This reply has been marked as private.August 2, 2014 at 7:10 am #10745This reply has been marked as private.August 2, 2014 at 7:21 am #10747Hi
Don’t worry about the error I was getting: Warning: _() expects exactly 1 parameter, 2 given in …./functions.php on line 161
I fixed it. On that line I added another underscore to $errors[‘captcha’] = _( ‘Please complete the CAPTCHA.’, ‘yourtextdomain’ ); and that fixed it up.
Cheers,
Reena
August 2, 2014 at 5:39 pm #10795Thanks for spotting this, I’ve corrected on the tutorial and reported the error to the pugin developer.
Thx
September 17, 2014 at 2:02 am #15640Hi Paolo,
i am trying really hard to get this going but without success. I followed your steps, the captcha shows up but it like ignored, you dont have to enter anything there to register.
Has anything changed? Or is there some simpler method to do add recaptcha?
Maybe post the whole reg_frm.php and child functions.php file code? I mean after the changes…
September 17, 2014 at 2:37 am #15641I’m using a customized WP (default) login/registration page and don’t remember whether this worked on the GD version or not, but the BestWebSoft Captcha is a nice plug-n-play version that should work across the site.
A simple check box will configure it to automatically be pulled into login, registration, password reset, and comment forms.
cheers
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket