How to use Joomla recaptcha plugin with my custom module?

后端 未结 3 1448
轮回少年
轮回少年 2020-12-02 23:32

I have created a custom module for my contactus form. Now I want to use Joomla recaptcha plugin with this module.

Any idea how to get this done?

3条回答
  •  不思量自难忘°
    2020-12-03 00:05

    In order to use joomla default recaptcha plugin follow these steps-

    1)Get recaptcha keys from http://www.google.com/recaptcha

    2)Set these keys to recaptcha plugin and activate it if it's not.

    3)Put below code where you want to show recaptcha

    //php code
    JPluginHelper::importPlugin('captcha');
    $dispatcher = JDispatcher::getInstance();
    $dispatcher->trigger('onInit','dynamic_recaptcha_1');
    
    //html code inside form tag
    

    4)Put this code where you validating/processing the form

    $post = JRequest::get('post');      
    JPluginHelper::importPlugin('captcha');
    $dispatcher = JDispatcher::getInstance();
    $res = $dispatcher->trigger('onCheckAnswer',$post['recaptcha_response_field']);
    if(!$res[0]){
        die('Invalid Captcha');
    }
    

    //For Joomla 3.x

    $post = JFactory::getApplication()->input->post;
    $dispatcher = JEventDispatcher::getInstance();
    

提交回复
热议问题