Answer the question
In order to leave comments, you need to log in
I get an error when submitting the registration form?
----------
Signup.php model code
<?php
class Signup extends Model
{
public $email;
public $password;
public function rules()
{
return[
[['email', 'password'], 'required'],
['email', 'email'],
['email', 'unique', 'targetClass' => 'app\Models\User'],
['password', 'string', 'min' => 2, 'max' => 10]
];
}
public function signup()
{
$user = new User();
$user->email = $this->email;
$user->password = $this->password;
return $user->save();
}
}
<?php
public function actionSignup()
{
$model = new Signup();
if (isset($_POST['Signup']))
{
$model->attributes = Yii::$app->request->post('Signup');
if ($model->validate() && $model->signup())
{
return $this->goHome();
}
}
return $this->render('signup',
['model'=>$model]);
}
<br><br>
<?php<br><br>
$form = ActiveForm::begin(['class' => 'form-horizontal']);<br><br>
$form->field($model, 'email')->textInput(['autofocus'=>true]); <br><br>
$form->field($model, 'password')->passwordInput(); <br><br>Register<br><br>
ActiveForm::end();<br><br>
Answer the question
In order to leave comments, you need to log in
Swears at this line
and either you don't have app\Models\User or it has wrong namespace
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question