D
D
Doniyor Mamatkulov2018-03-15 20:34:41
Yii
Doniyor Mamatkulov, 2018-03-15 20:34:41

Submit form doesn't work. Why?

Hello!
There is a form with different elements. When you click on the submit button - the page is reloaded and not submitted, i.e. I don't get into the $model->load condition at all. Why is that?
I open and close the form like this:

<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?>
<?php ActiveForm::end(); ?>

This is what is in the controller:
$this->view->title = Yii::$app->params['applicationName'].' | '.Yii::t('app', 'Documents circulation');
            $model = new Documents();
            if($model->load(Yii::$app->request->post()) && $model->validate()) {
                echo 'submitted!';
            }
            return $this->render('new', compact('model'));

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arman, 2018-03-15
@doniyorbekm

This means that loading or validation does not work, the validator interferes somewhere and you do not show its field or its errors.
Try in the controller before rendering to see what's wrong with the model:

if($_POST) {
    header('content-type: text/html; charset=utf-8');
    echo '<pre>';
    @print_r($model);
    echo '</pre>';
    exit(__FILE__ . ': ' . __LINE__);
}

or immediately ask for all errors ->getErrors

D
Dmitry, 2018-03-15
@slo_nik

Good evening.
So you are not validating, most likely.
Show the validation rules and what fields you have in the form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question