Captcha for registration form

This topic contains 30 replies, has 8 voices, and was last updated by  Paolo 9 years, 4 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #10313

    nasc
    Expired Member
    Post count: 235

    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,

    #10339

    Guust
    Moderator
    Post count: 29970
    #10421

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    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

    #10431

    Paolo
    Site Admin
    Post count: 31206

    to fix the reCaptcha styling issue add to your child theme style.css

    
    
    #recaptcha_response_field {
        display: inline;
        height: 20px;
    }

    Thx

    #10448

    nasc
    Expired Member
    Post count: 235

    Is 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.

    #10450

    Paolo
    Site Admin
    Post count: 31206

    Looks longer than it really is… It took me 2 minutes to do it and 5 to write the tutorial 🙂

    #10453

    nasc
    Expired Member
    Post count: 235

    I 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.css

    #10456

    Paolo
    Site Admin
    Post count: 31206

    Hi Nasc,

    that’s normal, you need to create it via FTP client before moving copied file in it.

    Thx

    #10472

    nasc
    Expired Member
    Post count: 235

    Thought I had it licked, Apparently not. My site no longer loads.

    I will see If I can’t put it back to square one.

    #10536

    nasc
    Expired Member
    Post count: 235
    This reply has been marked as private.
    #10745

    Reena
    Free User
    Post count: 32
    This reply has been marked as private.
    #10747

    Reena
    Free User
    Post count: 32

    Hi

    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

    #10795

    Paolo
    Site Admin
    Post count: 31206

    Thanks for spotting this, I’ve corrected on the tutorial and reported the error to the pugin developer.

    Thx

    #15640

    Adam
    Buyer
    Post count: 88

    Hi 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…

    #15641

    identity
    Lifetime Member
    Post count: 445

    I’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

Viewing 15 posts - 1 through 15 (of 31 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket