mercredi 10 août 2016

failed to make form in yii2

I have added this code in my editor the location is in app\models\FormAntri

<?php

  namespace app\models;

  use Yii;
  use yii\base\Model;

  class FormAntri extends Model
  {
 public $nama;
 public $email;

 public function rules()
 {
  return [
  [['nama', 'email'], 'required'],
  ['email', 'email'],
];
}
}

this code also in app\models\controllers/SiteController

public function actionAntri()
{
  $model = new FormAntri();

  if ($model->load(Yii::$app->request->post()) && $model->validate()){
    return $this->render('antri-ok',['model' => $model]);
  }else{
    return $this->render('antri', ['model' => $model]);
  }
}

I also added this code in views/site/antri.php

<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'nama') ?>
<?= $form->field($model, 'email') ?>

<div class="form-group">
 <?= Html::submitButton('Ok', ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end(); ?>

I added this too in view/site/antri-ok.php

<?php
use yii\helpers\Html;
?>
<p>Informasi yang sudah anda kirim adalah :</p>

<ul>
  <li><label>Nama</label>: <?= Html::encode($model->nama) ?></li>
  <li><label>Email</label>: <?= Html::encode($model->email) ?></li>
</ul>

but when I run http://localhost/advanced/backend/web/index.php?r=site/antri the result came like this enter image description here

what's wrong with that?

Aucun commentaire:

Enregistrer un commentaire