我有一个表单,在单击提交按钮时没有提交,但它正在验证。
见下表:
<?php
$form = ActiveForm::begin([
'id' => 'contact-form',
'action' => ['site/index'],
'options' => [
'class' => 'contact-form wow fadeInUp',
'data-row-duration' => '1s',
]
])
?>
<div class="form-validation alert">
<div class="form-group col-md-12">
<?=
$form->field($model, 'name', [
'options' => ['style' => 'margin:0;padding:0'],
'inputOptions' => [
'class' => 'form-control',
'placeholder' => 'Full Name',
'autocomplete' => 'off'
]
])->label(false)
?>
</div>
<div class="form-group col-md-6">
<?=
$form->field($model, 'email', [
'options' => ['style' => 'margin:0;padding:0'],
'inputOptions' => [
'class' => 'form-control',
'placeholder' => 'Email',
'autocomplete' => 'off'
]
])->label(false)
?>
</div>
<div class="form-group col-md-6">
<?=
$form->field($model, 'phone', [
'options' => ['style' => 'margin:0;padding:0'],
'inputOptions' => [
'class' => 'form-control',
'placeholder' => 'Phone',
'autocomplete' => 'off'
]
])->label(false)
?>
</div>
<div class="form-group col-md-12">
<?=
$form->field($model, 'name', [
'options' => ['style' => 'margin:0;padding:0'],
'inputOptions' => [
'class' => 'form-control',
'placeholder' => 'Message',
'autocomplete' => 'off',
'rows' => '5'
]
])->textarea()->label(false)
?>
</div>
<div class="form-group col-md-4 col-md-offset-8">
<?=Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
<?php ActiveForm::end(); ?>
SiteController/actionIndex:
public function actionIndex() {
$model = new ContactForm;
if( $model->load(Yii::$app->request->post()) && $model->validate() ){
if( $model->sendEmail(Yii::$app->params['adminEmail']) ){
Yii::$app->session->setFlash('success', 'Thank you for reaching us. We will respond to you shortly');
} else{
Yii::$app->session->setFlash('error', 'Something went wrong. Message not send successfuly');
}
return $this->refresh();
} else{
return $this->render('index', ['model' => $model]);
}
}
注意:我没有收到任何错误。它正在验证,但是在填写表单以单击提交后,该按钮不起作用,我什至使用die()
它来代替Yii::$app->session->setFlash()
仍然没有发生任何事情。它只是没有响应。