$tags_id = $model->tags;
$tags_arr = explode(", ", $tags_id);
foreach ($tags_arr as $tag) {
$issert_row[] = [$model->id,$tag];
}
Yii::$app->db->createCommand()->batchInsert('news_tags',['news_id','tags_id'],$issert_row)->execute();
foreach ($tags_arr as $tag) {
$tranzit_model = new NewsTags();
$tranzit_model->news_id = 6;
$tranzit_model->tags_id = $tag;
$tranzit_model->save();
}
// Капча
'reCaptcha' => [
'name' => 'reCaptcha',
'class' => 'himiklab\yii2\recaptcha\ReCaptcha',
'siteKey' => '6LcyeS0UAAAAAGtTPNZ6AUyIhH3itXXXXXXX,
'secret' => '6LcyeS0UAAAAAG0ugrwlS9p9_-9yO_XXXXXXX',
],
// Правила
public $image;
public $reCaptcha;
public function rules()
{
return [
//Обязательные к заполнению
[['review','name','city'], 'required', 'message' => 'Поле не может быть пустым ↓'],
// Проверяем длину сообщения
[['review'], 'string', 'length' => [100, 400], 'tooLong' => 'Сообщение не должно
превышать 400 символов','tooShort' => 'Сообщение должно содержать минимум 100
символов'],
[['name','city'], 'string'],
//Формат изображения
[['image'], 'file', 'extensions' => 'png, jpg'],
[['reCaptcha'], \himiklab\yii2\recaptcha\ReCaptchaValidator::className()]
];
}
<?php $form = ActiveForm::begin([
'id' => 'rew-form',
'layout' => 'horizontal',
'options' => ['class' => 'modal_rewiews_input','enctype' => 'multipart/form-data'],
'fieldConfig' => [
'template' => "{error}\n{input}",
'labelOptions' => ['class' => ''],
],
]) ?>
<?= $form->field($model, 'image')->fileInput(['class' => 'upload modal_rewiews_input','id' => 'files'])->label(false);?>
<div class="rew_img_input">
</div>
<?= $form->field($model, 'name')->textInput(['placeholder' => 'Имя фамилия'])-
>label(false) ?>
<?= $form->field($model, 'city')->textInput(['placeholder' => 'Город'])->label(false) ?>
<?= $form->field($model, 'review')->textarea(['rows' => 4, 'id' => 'good_reviews',
'placeholder' => 'Хорошие отзывы'])->label(false) ?>
<?= \himiklab\yii2\recaptcha\ReCaptcha::widget(['name' => 'reCaptcha']) ?>
<div class="form-group">
<?= Html::submitButton('Оставить отзыв', ['class' => 'btn btn-primary main_btn
form_btn', 'name' => 'button']) ?>
</div>
<?php $form = ActiveForm::end() ?>
public function rules()
{
return [
// ...
[[], \himiklab\yii2\recaptcha\ReCaptchaValidator::className()]
];
}
public $reCaptcha;
public function rules()
{
return [
// ...
[['reCaptcha'], \himiklab\yii2\recaptcha\ReCaptchaValidator::className(), 'secret' => 'your secret key', 'uncheckedMessage' => 'Please confirm that you are not a bot.']
];
}