Open srakl opened 1 year ago
How do i get yii2-usuario recaptcha to work with Ajax posts?
Recaptcha
in my model i have this
public $captcha; public function rules() { return [ [['captcha'], 'required'], [['captcha'], 'Da\User\Validator\ReCaptchaValidator'], .... ]; }
in my view
use Da\User\Widget\ReCaptchaWidget; <form> <?= $form->field($model, 'captcha')->widget(ReCaptchaWidget::class, ['theme' => 'light'])->label(false) ?> </form> <script> $(document).ready(function () { var $form = $("#<?= $model->formName() ?>"); $form.on("submit", function (event, messages) { event.preventDefault(); $.ajax({ "type":"POST", "url":$form.attr('action'), "data":$form.serialize(), "dataType":"json", "success":function(data){ $("#tax").html(data.tax); }, }); return false; }); }); </script>
in my controller
$model = new calcForm; $model->scenario = calcForm::SCENARIO_CALC; if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { if ($model->validate()) { .... } }
How do i get the validation to work with an ajax post? $model->validate() in my controller doesn't seem to validate the captcha. Thanks
$model->validate()
How do i get yii2-usuario recaptcha to work with Ajax posts?
Recaptcha
in my model i have this
in my view
in my controller
How do i get the validation to work with an ajax post?
$model->validate()
in my controller doesn't seem to validate the captcha. Thanks