Answer the question
In order to leave comments, you need to log in
How to correctly implement the insertion of a record through a form?
When trying to insert a record based on the data entered in the form, the following error appears:
Here is the method I created to process the request:
public function actionCreateUser()
{
$this->PageTitle = "Регистрация";
$user = new User();
if(isset($_POST['User']))
{
$user->attributes = $_POST['User'];
if($user->save())
$this->redirect(array('user/index'));
}
$this->render('CreateUser', array('user' => $user,));
}
<div class="form">
<?php echo CHtml::beginForm(array("SiteController/CreateUser", "POST")) ?>
<div class="row"><?php
echo CHtml::activeLabelEx($user, "name");
echo CHtml::activeTextField($user, "name");
echo CHtml::error($user,"name");
?></div>
<div class="row"><?php
echo CHtml::activeLabelEx($user, "password");
echo CHtml::activeTextField($user, "password");
echo CHtml::error($user,"password");
?></div>
<div class="row"><?php
echo CHtml::activeLabelEx($user, "role");
echo CHtml::activeTextField($user, "role");
echo CHtml::error($user,"role");
?></div>
<?php echo CHtml::submitButton("Зарегистрироваться"); ?>
<?php echo CHtml::endForm() ?>
</div>
Answer the question
In order to leave comments, you need to log in
I think it's worth replacing SiteController/CreateUser with site/create-user
. You get a 404 error - page not found.
Do you have the page address and the address where the form is sent to match?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question