diff --git a/modules/guestbook/GuestbookModule.php b/modules/guestbook/GuestbookModule.php index 7239f86..ba58592 100644 --- a/modules/guestbook/GuestbookModule.php +++ b/modules/guestbook/GuestbookModule.php @@ -7,13 +7,13 @@ class GuestbookModule extends \yii\easyii\components\Module 'enableTitle' => false, 'enableEmail' => true, 'preModerate' => false, - 'enableCaptcha' => true, + 'enableCaptcha' => false, 'mailAdminOnNewPost' => true, 'subjectOnNewPost' => 'New message in the guestbook.', - 'templateOnNewPost' => '@easyii/modules/guestbook/en/mail/new_post', + 'templateOnNewPost' => '@easyii/modules/guestbook/mail/en/new_post', 'frontendGuestbookRoute' => '/guestbook', 'subjectNotifyUser' => 'Your post in the guestbook answered', - 'templateNotifyUser' => '@easyii/modules/guestbook/en/mail/notify_user' + 'templateNotifyUser' => '@easyii/modules/guestbook/mail/en/notify_user' ]; public static $installConfig = [ diff --git a/modules/guestbook/api/Guestbook.php b/modules/guestbook/api/Guestbook.php index 88d71a4..f05185c 100644 --- a/modules/guestbook/api/Guestbook.php +++ b/modules/guestbook/api/Guestbook.php @@ -99,6 +99,7 @@ public function api_form($options = []) public function api_save($data) { $model = new GuestbookModel($data); + $model->scenario = 'send'; if ($model->save()) { return ['result' => 'success']; } else { diff --git a/modules/guestbook/controllers/SendController.php b/modules/guestbook/controllers/SendController.php index 79b1d38..b9ecb74 100644 --- a/modules/guestbook/controllers/SendController.php +++ b/modules/guestbook/controllers/SendController.php @@ -9,6 +9,7 @@ class SendController extends \yii\web\Controller public function actionIndex() { $model = new GuestbookModel; + $model->scenario = 'send'; $request = Yii::$app->request; if ($model->load($request->post())) { diff --git a/modules/guestbook/models/Guestbook.php b/modules/guestbook/models/Guestbook.php index 0355eac..e7ae02f 100644 --- a/modules/guestbook/models/Guestbook.php +++ b/modules/guestbook/models/Guestbook.php @@ -31,7 +31,7 @@ public function rules() ['email', 'email'], ['title', 'string', 'max' => 128], ['reCaptcha', ReCaptchaValidator::className(), 'when' => function($model){ - return $model->isNewRecord && Yii::$app->getModule('admin')->activeModules['guestbook']->settings['enableCaptcha']; + return $model->scenario == 'send' && Yii::$app->getModule('admin')->activeModules['guestbook']->settings['enableCaptcha']; }], ]; }