0
votes
<?php $form = ActiveForm::begin(['options' => ['action'=>'SiteController/actionUploadImage','method'=>'post','enctype' => 'multipart/form-data']]) ?>

<?= $form->field($model, 'image')->fileInput() ?>

<button>Submit</button>

<?php ActiveForm::end() ?>

This is my form, in inspect element action not showing.

2

2 Answers

3
votes

There are 2 main problems in your code.

The first one is, that the array with url should have format of ['controller-id/action-id'] but your url has format ['ControllerClass/actionMethod'].

The second one is the position of action in your array. As Sfili_81 mentioned in his answer https://stackoverflow.com/a/58797242/11977068

So the correct code should look like:

$form = ActiveForm::begin([
    'action' => ['site/upload-image'],
    'method' => 'post',
    'options' => ['enctype' => 'multipart/form-data'],
]);

Also since yii 2.0.8 there is no need to explicitily use enctype option if you are using ActiveForm. Calling $form->field(...)->fileInput() will ensure the correct enctype.

0
votes

You have to write action outside the options like this:

<?php $form = ActiveForm::begin(['action' => ['SiteController/actionUploadImage'],'method' => 'post']) ?>

[documentation]