I created a simple form with simple rules declared in model, but when I tried to submit, It is not working, I don't encountered an error also. The expected output should be the session flash, but nothing happened in my case
This is my controller
public function actionCustomer()
{
$model = new CustomerForm;
if($model->load(Yii::$app->request->post()) && $model->validate())
{
Yii::$app->session->setFlash('success','you entered it correctly');
}
return $this->render('customerForm',['model'=>$model]);
}
This is my Model
<?php
namespace app\models;
use yii\base\Model;
class CustomerForm extends Model
{
public $name;
public $email;
public function rules()
{
return [
[['name', 'email'], 'required'],
['email', 'email'],
];
}
}
This is my view
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php
if(Yii::$app->session->hasFlash('success')){
echo Yii::$app->session->getFlash('success');
}
?>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model,'name'); ?>
<?= $form->field($model,'email'); ?>
<?= Html::submitButton('Submit',['class'=>'btn btn-success']); ?>