F
F
funtik522016-03-04 10:12:53
Yii
funtik52, 2016-03-04 10:12:53

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:
06d40abae88841adbb79e734ddf19e29.png
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,));
  }

And here is the template in which the data is entered:
<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>

I'm learning the web from a book. After reviewing all the topics came to a logical impasse. The form seems to work fine - yes, it provides a default value for the "role" field. But after clicking on the "Register" button, an error occurs.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Arutyunov, 2016-03-04
@funtik52

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 question

Ask a Question

731 491 924 answers to any question