PHP code example of richweber / yii2-recaptcha

1. Go to this page and download the library: Download richweber/yii2-recaptcha 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/ */

    

richweber / yii2-recaptcha example snippets


'components' => [
    ...
    'recaptcha' => [
        'class' => 'richweber\recaptcha\ReCaptcha',
        'siteKey' => 'https://www.google.com/recaptcha/admin',
        'secretKey' => 'https://www.google.com/recaptcha/admin',
        'errorMessage' => 'Are you robot?',
    ],
    ...
],

use richweber\recaptcha\Captcha;

 $form = ActiveForm::begin(['id' => 'contact-form']); 

public function actionContact()
{
    $model = new ContactForm();
    if (
        $model->load(Yii::$app->request->post())
        && Yii::$app->recaptcha->verifyResponse(
            $_SERVER['REMOTE_ADDR'],
            Yii::$app->request->post('g-recaptcha-response'))
        && $model->contact(Yii::$app->params['adminEmail'])
    ) {
        Yii::$app->session->setFlash('contactFormSubmitted');

        return $this->refresh();
    } else {
        return $this->render('contact', [
            'model' => $model,
        ]);
    }
}

$ php composer.phar