1.buat model, dg variable public name dan email
ada rule name, email yg required dan email yg benar
namespace frontend\models;
use Yii;
use yii\base\Model;
class EntryForm extends Model
{
public $name;
public $email;
public function rules()
{
return [
[['name', 'email'], 'required'],
['email', 'email'],
];
}
}
2. buat action di siteController
public function actionEntry()
{
$model = new EntryForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
// valid data received in $model
// do something meaningful here about $model ...
return $this->render('entry-confirm', ['model' => $model]);
} else {
// either the page is initially displayed or there is some validation error
return $this->render('entry', ['model' => $model]);
}
}
tampak di sana ada 2 view = entry dan entry-confirm
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
field($model, 'name')->label('Your Name') ?>
field($model, 'email')->label('Your Email') ?>
'btn btn-primary']) ?>
ActiveForm menghandle dengan baik, perhatikan begin() dan end()
utk entry-confirm:
use yii\helpers\Html;
?>
You have entered the following information:
- : name) ?>
- : email) ?>
No comments:
Post a Comment