Home » Web Design and Development » Search Engine Optimisation ( SEO ) » Adding Google Recaptcha to yclas register form

Adding Google Recaptcha to yclas register form

This post shows minimum changes required in source code to add google recaptcha in the register form of yclass.

Modify themes/reclassifieds3/views/pages/auth/register-form.php to add below code

    <?if (core::config('advertisement.captcha') != FALSE):?>
        <div class="form-group">    
            <?=FORM::label('captcha', __('Captcha'), array('class'=>'col-sm-2 control-label', 'for'=>'captcha'))?>
            <div class="col-md-5 col-sm-6">
                <?if (Core::config('general.recaptcha_active')):?>
                    <?=Captcha::recaptcha_display()?>
                <?else:?>                   
                    <?=captcha::image_tag('register_new')?><br />
                    <?= FORM::input('captcha', "", array('class'=>'form-control', 'id' => 'register_new', 'required'))?>
                <?endif?>                   
            </div>                      
        </div>                      
    <?endif?>

Then modify ./oc/classes/controller/panel/auth.php to make sure that this recaptch check is successful by adding below code,

public function action_register() {
    //if user loged in redirect home
    if (Auth::instance()->logged_in()) {
       $this->redirect(Route::get('oc-panel')->uri());
    } elseif ($this->request->post()) {
       if(captcha::check('register_new'))
       {
       } else {
           Alert::set(Alert::ALERT, __('Captcha is not correct'));
       }
    }
}

Above code will add recaptcha to user registration for and only if recaptcha is successful then user registrations will be successful.


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment