Callme
registerJs("
$(document).on('click', '.js_openWindowModal', function (event) {
event.preventDefault();
$('#windowModal').modal('show').find('.modal-content').load($(this).attr('href'));
});
");
?>
public function actionCallme() {
$model = new CallForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
try {
$this->service->create($model);
if (Yii::$app->request->isAjax) {
return Json::encode(array('status' => 'success', 'type' => 'success', 'message' => 'Created successfully.'));
}
else {
Yii::$app->session->setFlash('success', 'Данные изменены');
$url = Url::previous();
return $this->redirect($url ?: Url::to(['index']));
}
} catch (Exception $ex) {
Yii::$app->errorHandler->logException($e);
if (Yii::$app->request->isAjax) {
return Json::encode(array('status' => 'warning', 'type' => 'warning', 'message' => 'Can not created.'));
} else {
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
}
if (Yii::$app->request->isAjax) {
return $this->renderAjax('view', [
'model' => $model,
]);
} else {
return $this->render('view', [
'model' => $model,
]);
}
}
use yii\bootstrap4\ActiveForm;
'callme-form','options'=>['class'=>'js_modalForm']]); ?>
Modal title
= $form->field($model, 'name')->textInput(['autofocus' => true]) ?>
= $form->field($model, 'email') ?>
= $form->field($model, 'subject') ?>
= $form->field($model, 'body')->textarea(['rows' => 6]) ?>
= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'template' => '{image}{input}',
]) ?>
registerJS("
$(document).on('beforeSubmit', '.js_modalForm', function (event) {
event.preventDefault();
var form = $(this);
$.ajax({
url: form.attr('action'),
cache: false,
contentType: false,
processData: false,
data: form.serialize(),
type: 'post',
beforeSend: function() {
},
success: function(response){
toastr.success('',response.message);
$('#windowModal').modal('hide');
},
complete: function() {
},
error: function (data) {
toastr.warning('','There may a error on uploading. Try again later');
}
});
return false;
});
");
?>