when I press submit button noting happens, even the page doesn't refresh. I have checked the code too many times. I don't know what is wrong with it. I am using Yii2 framework the basic-app and Apache server.
Controller:
<?php
namespace app\controllers;
use Yii;
use yii\web\controller;
use app\models\Form;
class FormController extends Controller{
public function actionForm(){
$model = new Form;
if($model->load(Yii::$app->request->post()) && $model->validate()){
Yii::$app->session->setFlash('success', 'You have entered data successfuly!');
}
return $this->render('view',['model'=>$model]);
}
}
?>
Model:
<?php
namespace app\models;
use yii\base\model;
class Form extends Model{
public $name;
public $email;
public function rules(){
return [
[['name','email'],'required'],
['email','email']
];
}
}
?>
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']); ?>
You forgot to add
at the end.