I know this is a dumb question, but I just started learning with Yii2. I haven't found any useful information here related to this, so. What I need to do is display a message if the user was added to the database successfuly. Could somoene help me to solve this? I've no idea where it has to be written: in a model
, controller
or view
.
Here is my controller action
:
public function actionCreate()
{
$model = new Employee();
$model->scenario = Employee::SCENARIO_CREATE;
$post = Yii::$app->request->post();
if ($model->load($post) && $model->save()) {
return $this->redirect(['create']);
}
return $this->render('create', [
'model' => $model,
]);
}
Here is my view
:
<div class="employee-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->textInput([
'maxlength' => 50,
]) ?>
<?= $form->field($model, 'surname')->textInput([
'maxlength' => 50,
]) ?>
<?= $form->field($model, 'employment_date')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
Now what is happening is that the script doesn't allow to enter the date, which is later than today's date and also doesn't allow to enter a string into the date field. So to be clear, if the user has entered correct information, I need to add the message that would say "Users has been entered to the database successfully".
Thanks for any help!