Answer the question
In order to leave comments, you need to log in
Yii2 form processing without ActiveForm?
All good. I started to pick Yii, not without the help of kind people, an unpleasant feature was discovered - bootstrap 4 is not supported. I installed the component, registered the configs, everything works fine. Until I insert the widget. As soon as I insert a widget - an error
Method yii\widgets\ActiveField::__toString() must not throw an exception, caught Error: Call to a member function isAttributeRequired() on null
<?use yii\widgets\ActiveForm;?>
....
<?
$form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'landing-form auth align-middle'],
]) ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('Вход', ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end() ?>
//В use всё подключено
public function actionLogin() {
return $this->render("landing");
$model = new LoginForm();
if ($model->load(Yii::$app->request->post() && $model->validate())) {
return $this->goBack();
}
return $this->render('landing', [
'model' => $model,
]);
}
<?php
namespace app\models;
use Yii;
use yii\base\Model;
/**
* LoginForm is the model behind the login form.
*
* @property User|null $user This property is read-only.
*
*/
class LoginForm extends Model
{
public $username;
public $password;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
];
}
public function validate()
{
return true;
}
}
?>
Answer the question
In order to leave comments, you need to log in
Your mistake is here
public function actionLogin() {
return $this->render("landing");
// ......
return $this->render('landing', [
'model' => $model,
]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question