I
I
Ivan Yakushenko2016-07-17 15:23:14
Yii
Ivan Yakushenko, 2016-07-17 15:23:14

Why is $_GET passed instead of $_POST?

There is a form in the view file that is responsible for passing the model data entered in the field to adding it to the database:

<form>
<?php $form = ActiveForm::begin(['action' =>['site/editdata'], 'id' => 'form-editdata', 'method' => 'post',]); ?>
    <div class="input-block">
        <p>Фамилия и Имя Отчество*</p>
        <p><?php echo Yii::$app->user->identity->fio;?></p><br>
        <input type="text" name="EditdataForm[fio]" class="input__item">
    </div>
    <div class="input-block clearfix">
        <div class="col-sm-6">
            <div class="left-input">
            <div class="row">
                <p>Мобильный телефон*</p>
                   <p><?php echo Yii::$app->user->identity->phone;?></p><br>
                    <input type="text" name="EditdataForm[phone]" class="input__item">
            </div>
        </div>
    </div>
    <div class="col-sm-6">
        <div class="row">
            <div class="right-input">
                <div class="post-input">
                    <p>Электронная почта *</p>
                    <p><?php echo Yii::$app->user->identity->email;?></p><br>
                    <input type="text" name="EditdataForm[email]" class="input__item">
                </div>
            </div>
        </div>
    </div>
    <div class="input-block">
        <?= Html::submitButton('Сохранить', ['class' => 'save__btn', 'name' => 'editdata-button']) ?>
    </div>
<?php ActiveForm::end(); ?>
</form>

The site/editdata code is as follows:
<?php $form = ActiveForm::begin(['id' => 'form-editdata']); ?>
    <?= $form->field($model, 'fio')->textInput(['autofocus' => true]) ?>
    <?= $form->field($model, 'email') ?>
    <?= $form->field($model, 'street') ?>
    <?= $form->field($model, 'house') ?>
    <?= $form->field($model, 'housing') ?>
    <?= $form->field($model, 'apartment') ?>
    <?= $form->field($model, 'phone') ?>
    <?= $form->field($model, 'password')->passwordInput() ?>
    <div class="form-group">
        <?= Html::submitButton('Edit', ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?>
    </div>
<?php ActiveForm::end(); ?>

EditdataForm model function:
public function editdata()
{
    if (!$this->validate()) {
        return null;
    }

    $user = new User();
    $user->username = $this->username;
    $user->email = $this->email;
    $user->fio = $this->fio;
    $user->apartment = $this->apartment;
    $user->house = $this->house;
    $user->housing = $this->housing;
    $user->street = $this->street;
    $user->phone = $this->phone;
    $user->setPassword($this->password);
    return $user->save() ? $user : null;
}

And controller:
public function actionEditdata()
{
    return $this->render('editdata');
}

By clicking the "Save" button, instead of sending a $_POST request, a $_GET is generated, which is written to the address bar, $_POST is empty.
Absolutely the same registration implementation works, that is, it generates a $_POST request and passes it where necessary.
The only thing is that the page on which the original form is located is part of the module and is located at the address modules/privateCabinet/views, but I don’t think that this should somehow affect the fact that $_GET is passed instead of $_POST, although it is indicated back in the form:
ActiveForm::begin(['action' =>['site/editdata'], 'id' => 'form-editdata', 'method' => 'post',])

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Milok Murlyka, 2016-07-17
@milokmurlika

See what you get in HTML

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question