Home>

Controller sitecontroller:

class sitecontroller extends controller
{
  //...
  public function actions ()
  {
    return [
      //...
      "captcha" =>[
        "class" =>"yii \ captcha \ captchaaction",        "fixedverifycode" =>yii_env_test?"testme":null,      ],    ];
  }
  //...
}
?>

Define the form model:

class contactform extends model
{
  //...
  public $verifycode;
  //...
  public function rules ()
  {
    return [
      //...
      ["verifycode", "captcha"],    ];
  }
  //...
}
?>

Call the method in the view:

$form=activeform ::begin (["id" =>"contact-form"]);?>
//...
$form->field ($model, "verifycode")->widget (captcha ::classname ())?>
//...
activeform ::end ();?>
php
  • Previous AngularJS instructions in detail
  • Next Simple usage example of DropDownList in Yii2