Adding and customizing CaptchaWidget
Nowadays, on the Internet, if you leave a form without spam protection, you will get a ton of spam data entered in a short time. Yii includes a Captcha component that makes adding such protection a breeze. The only problem is that there is no systematic guide on how to use it.
In the following example, we will add Captcha protection to a simple form.
Getting ready
Create a new application by using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
Create a form model,
@app/models/EmailForm.php
, as follows:<?php namespace app\models; use yii\base\Model; class EmailForm extends Model { public $email; public function rules() { return [ ['email', 'email'] ]; } }
Create a controller,
@app/controllers/EmailController.php
, as follows:<?php namespace app\controllers; use Yii; use yii\web\Controller; use app\models\EmailForm; class EmailController...