Есть такая задачка, никак не могу решить...
Есть модель
Код: Выделить всё
<?php
namespace frontend\models;
use yii\base\Model;
class PsychologistForm extends Model
{
public $name;
public $phone;
public $email;
public $reCaptcha;
public function rules()
{
return [
[['name', 'phone', 'email'], 'required'],
['name', 'string'],
['email', 'email'],
['name', 'trim'],
[['reCaptcha'], \himiklab\yii2\recaptcha\ReCaptchaValidator::className(), 'secret' => 'your secret key', 'uncheckedMessage' => 'Please confirm that you are not a bot.']
];
}
public function attributeLabels()
{
return [
'name' => 'Имя',
'phone' => 'Телефон',
'email' => 'Ваш E-mail',
];
}
}
Код: Выделить всё
<?php
use yii\widgets\ActiveForm;
use yii\widgets\MaskedInput;
use frontend\models\PsychologistForm;
$model = new PsychologistForm();
?>
<div class="col-sm-6 col-md-4">
<?php $form = ActiveForm::begin([
'validateOnBlur' => false,
'id' => 'psychologist-form',
'action' => ['/site/psychologist-consultation/'],
'errorCssClass' => 'error',
'options' => [
'class' => 'consultation'
]
]); ?>
<p>Заказать консультацию психолога</p>
<?= $form->field($model, 'name', ['template' => '{input}'])->textInput(['placeholder' => 'Имя'])->label(false) ?>
<?= $form->field($model, 'email', ['template' => '{input}'])->textInput(['placeholder' => 'Ваш E-mail'])->label(false) ?>
<?= $form->field($model, 'phone', ['template' => '{input}'])->widget(MaskedInput::className(), [
'name' => 'phone',
'mask' => '+9 (999) 999 9999',
])->input('tel', ['placeholder' => 'Телефон'])->label(false) ?>
<!-- Button to Open the Modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Open modal
</button>
<!-- The Modal -->
<div class="modal" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Modal Heading</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<?= $form->field($model, 'reCaptcha')->widget(
\himiklab\yii2\recaptcha\ReCaptcha::className(),
['siteKey' => 'your siteKey']
) ?>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="submit">Заказать</button>
</div>
</div>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
Кнопка открытия модалки срабатывает всегда, а надо только после валидации обязательных полей