# How to add captcha to form Adding captcha to forms is pretty easy and can be done in three steps: 1. Add new field and validation rule in the model 2. Show captcha in view 3. Add captcha action in controller In this guide I would like to show you how to add captcha field in the registration form but you can add captcha to any form following this steps. > **NOTE:** Captcha will not work with ajax validation enabled ([see](https://github.com/yiisoft/yii2/blob/master/framework/captcha/CaptchaValidator.php#L20)). You should not enable it in active form configuration array. ## 1. Adding field and validation rules to model First of all you need to override Registration form as described in special guide. After this done you have to add public property named **captcha** and validation rules. ```php title = Yii::t('user', 'Sign up'); $this->params['breadcrumbs'][] = $this->title; ?>

title) ?>

'registration-form', ]); ?> field($model, 'username') ?> field($model, 'email') ?> field($model, 'password')->passwordInput() ?> field($model, 'captcha')->widget(Captcha::className(), [ 'captchaAction' => ['/site/captcha'] ]) ?> 'btn btn-success btn-block']) ?>

``` ## 3. Adding action to the controller In order to make captcha work you have to add captcha action to `app\controllers\SiteController` Maybe it is already added because standard Yii2 application template adds it automatically. ```php [ 'class' => 'yii\captcha\CaptchaAction', ], ]; } ... } ```