Answer the question
In order to leave comments, you need to log in
Data is not filled in the database from the Yii2 form?
Dear gentlemen, programmers
Who is not difficult to help
I need to make sure that the data from the form is filled in the database.
Here is the model
class Userts extends ActiveRecord
{
public $id;
public $name;
public $password;
public $password_repeat;
public $email;
public $wallet;
public $amount_of_tikets;
public $is_admin;
public static function tableName()
{
return'{{%user}}';
}
public function attributeLabels()
{
return[
'name' => 'User',
'password' => 'Password',
'password_repeat' => 'Password repeat',
'email' => 'Email',
'wallet' => 'Wallet',
'amount_of_tickets' => 'Amount of tickets',
'is_admin' => 'Is Admin'
];
}
public function rules()
{
return[
[['name','password','email'],'required'],
['password','compare','compareAttribute' => 'password_repeat'],
['email','email']
];
}
}
class UserController extends Controller
{
public function actionReg()
{
$model = new Userts;
if (\Yii::$app->getRequest()->isPost)
{
if($model->load(\Yii::$app->request->post()) && $model->validate())
{
$model->save(false);
}
}
return $this->render('reg',compact('model'));
}
}
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'form-horizontal'],
'action' => ['user/reg'],
'method' => 'post'
]) ?>
<?= $form->field($model, 'name')->textInput() ?>
<?= $form->field($model, 'email')->input('email') ?>
<?= $form->field($model, 'password')->passwordInput()?>
<?= $form->field($model, 'password_repeat')->passwordInput()?>
<?= Html::submitButton('Send', ['class' => 'btn btn-success']) ?>
<?php ActiveForm::end() ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question