0
votes

I am trying to use https://github.com/himiklab/yii2-recaptcha-widget for YII2 framework. Currently i am building a contact form, so i followed instruction there. However i faced a problem, by the instruction

public $reCaptcha;

public function rules()
{
  return [
      // ...
      [['reCaptcha'], \himiklab\yii2\recaptcha\ReCaptchaValidator::className(), 'secret' => 'your secret key']
  ];
}

i have to add this in the model, but my contact form only exists in controller and view, i dont need a model to save the submission of feedback in database, so how can i do this verification of rules at controller layer?

1
Why ... ? Yii2 give you a validation schema .. .. why not follow it - ScaisEdge
thanks for giving the direction - onegun

1 Answers

0
votes

You can try to use ad hoc validation for that.

$validator = new \himiklab\yii2\recaptcha\ReCaptchaValidator;
$validator->secret = '...';

if ($validator->validate($entered_recaptcha_code, $error)) {
    // ok
} else {
    echo $error;
}

I have not tried it before, some additional configuration might be needed.