PHP code example of cgsmith / zf1-recaptcha-2

1. Go to this page and download the library: Download cgsmith/zf1-recaptcha-2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cgsmith / zf1-recaptcha-2 example snippets


public function _initView()
{
    $view = new Zend_View();

    $view->addHelperPath(
        APPLICATION_PATH . '/../vendor/cgsmith/zf1-recaptcha-2/src/Cgsmith/View/Helper',
        'Cgsmith\\View\\Helper\\'
    );

    Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_ViewRenderer($view));

    return $view;
}

public function _initRecaptcha()
{
    $config = \Zend_Registry::get('application');
    $params = $config->recaptcha->toArray();

    $params['messageTemplates'] = [
        \Cgsmith\Validate\Recaptcha::INVALID_CAPTCHA => 'The captcha was invalid', // set custom/translated message
        \Cgsmith\Validate\Recaptcha::CAPTCHA_EMPTY => 'The captcha must be completed'
    ];

    \Zend_Registry::set('recaptcha', $params);
}



// create your element
$this->addElement(new \Cgsmith\Form\Element\Recaptcha());


if($form->isValid($_POST)) {
	$values = $form->getValues();
	unset($values['g-recaptcha-response']);
	// Your business logic must be here
}