Commit 94154eea25121c168b6cf6e3887ef734717b50a4
1 parent
51db39f2
Добавление капчи к форме контактов Коммит из под сервера, потому что каптча на локале не работала
Showing
3 changed files
with
14 additions
and
8 deletions
Show diff stats
frontend/models/Feedback.php
| @@ -29,15 +29,16 @@ class Feedback extends ArtboxCoreFeedback | @@ -29,15 +29,16 @@ class Feedback extends ArtboxCoreFeedback | ||
| 29 | 'on' => self::SCENARIO_DEFAULT, | 29 | 'on' => self::SCENARIO_DEFAULT, |
| 30 | 'message' => \Yii::t('app', 'Empty field'), | 30 | 'message' => \Yii::t('app', 'Empty field'), |
| 31 | ], | 31 | ], |
| 32 | - ['reCaptcha', ReCaptchaValidator::className(), 'uncheckedMessage' => 'Please confirm that you are not a bot.', | 32 | + ['reCaptcha', ReCaptchaValidator::className(), |
| 33 | + 'uncheckedMessage' => 'Please confirm that you are not a bot.', | ||
| 33 | // add follow lines to prevent checking recaptcha when from has errors | 34 | // add follow lines to prevent checking recaptcha when from has errors |
| 34 | 'when' => function ($model) { | 35 | 'when' => function ($model) { |
| 35 | return !$model->hasErrors(); | 36 | return !$model->hasErrors(); |
| 36 | }, | 37 | }, |
| 37 | - | ||
| 38 | - | ||
| 39 | ], | 38 | ], |
| 40 | - | 39 | +// [ |
| 40 | +// 'reCaptcha','safe' | ||
| 41 | +// ], | ||
| 41 | [ | 42 | [ |
| 42 | [ | 43 | [ |
| 43 | 'name', | 44 | 'name', |
frontend/modules/forms/controllers/SaveController.php
| @@ -58,19 +58,20 @@ class SaveController extends Controller | @@ -58,19 +58,20 @@ class SaveController extends Controller | ||
| 58 | $this->sendEmail($model); | 58 | $this->sendEmail($model); |
| 59 | return ['status' => 'success']; | 59 | return ['status' => 'success']; |
| 60 | } else { | 60 | } else { |
| 61 | - if ($model->save()) { | 61 | + |
| 62 | + if ($model->save(false)) { | ||
| 62 | if ($this->module->sendEmail) { | 63 | if ($this->module->sendEmail) { |
| 63 | $this->sendEmail($model); | 64 | $this->sendEmail($model); |
| 64 | return ['status' => 'success']; | 65 | return ['status' => 'success']; |
| 65 | } | 66 | } |
| 66 | return ['status' => 'success']; | 67 | return ['status' => 'success']; |
| 67 | } else { | 68 | } else { |
| 68 | - return ['status' => 'error']; | 69 | + return ['status' => 'error','errors'=>$model->errors]; |
| 69 | } | 70 | } |
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | } | 73 | } |
| 73 | - return ['status' => 'error']; | 74 | + return ['status' => 'error','error' => 'if doesent work']; |
| 74 | } | 75 | } |
| 75 | 76 | ||
| 76 | /** | 77 | /** |
frontend/modules/forms/views/form/form.php
| @@ -7,7 +7,11 @@ | @@ -7,7 +7,11 @@ | ||
| 7 | use yii\helpers\Html; | 7 | use yii\helpers\Html; |
| 8 | use yii\widgets\ActiveForm; | 8 | use yii\widgets\ActiveForm; |
| 9 | 9 | ||
| 10 | -$form = ActiveForm::begin(['id' => 'dynamic-form']); | 10 | +$form = ActiveForm::begin([ |
| 11 | + 'id' => 'dynamic-form', | ||
| 12 | + 'enableAjaxValidation' => false, | ||
| 13 | + 'enableClientValidation' => true, | ||
| 14 | +]); | ||
| 11 | foreach ($this->context->module->attributes as $field) { | 15 | foreach ($this->context->module->attributes as $field) { |
| 12 | if (isset($types[$field])) { | 16 | if (isset($types[$field])) { |
| 13 | $function = $types[$field]['type']; | 17 | $function = $types[$field]['type']; |