php - Yii2 DynamicForm Input File Image always empty or NULL -


i'm using wbraganca yii2-dynamicform , kartik yii2-widget-fileinput. form works fine when i'm trying getinstance upload images null.

this controller.

public function addmultipleimage($model){        $modelsoptionvalue = model::createmultiple(optionvalue::classname());         model::loadmultiple($modelsoptionvalue, yii::$app->request->post());         foreach ($modelsoptionvalue $index => $modeloptionvalue) {             $modeloptionvalue->sort_order = $index;             $file[$index]=  uploadedfile::getinstancebyname("optionvalue[".$index."][upload_image]");             var_dump($file[$index]);           if($file[$index]){                 $ext = end((explode(".", $file[$index]->name)));                 // generate unique file name                 $modeloptionvalue->img= yii::$app->security->generaterandomstring().".{$ext}";                 $path[$index]= yii::getalias ('@web') ."/img/". $modeloptionvalue->img;             }else{                 return false;             }         } 

view form

  //_form.php   <?php $form = activeform::begin( [     'enableclientvalidation' => false,     'enableajaxvalidation' => true,     'validateonchange' => true,     'validateonblur' => false,     'options' => [         'enctype' => 'multipart/form-data',         'id' => 'dynamic-form'     ]      ]); ?>   //_form_add_image.php  <?php dynamicformwidget::begin([     'widgetcontainer' => 'dynamicform_wrapper',     'widgetbody' => '.form-options-body',     'widgetitem' => '.form-options-item',     'min' => 1,     'insertbutton' => '.add-item',     'deletebutton' => '.delete-item',     'model' => $modelsoptionvalue[0],     'formid' => 'dynamic-form',     'formfields' => [         'upload_image'     ], ]); ?>   <?= $form->field($modeloptionvalue, "[{$index}]upload_image")->label(false)->widget(fileinput::classname(), [                         'options' => [                             'multiple' => false,                             'accept' => 'image/*',                             'class' => 'optionvalue-img'                         ],                         'pluginoptions' => [                             'previewfiletype' => 'image',                             'showcaption' => false,                             'showupload' => false,                             'browseclass' => 'btn btn-default btn-sm',                             'browselabel' => ' seleccionar imagen',                             'browseicon' => '<i class="glyphicon glyphicon-picture"></i>',                             'removeclass' => 'btn btn-danger btn-sm',                             'removelabel' => ' borrar',                             'removeicon' => '<i class="fa fa-trash"></i>',                             'previewsettings' => [                                 'image' => ['width' => '138px', 'height' => 'auto']                             ],                             'initialpreview' => $initialpreview,                             'layouttemplates' => ['footer' => '']                         ]                     ]) ?> 

and model

public $upload_image; /**  * @inheritdoc  */ public static function tablename() {     return 'option_value'; }  /**  * @inheritdoc  */ public function rules() {     return [         [['upload_image'], 'file', 'extensions' => 'png, jpg', 'skiponempty' => true],         [['id_montacarga', 'sort_order'], 'integer']     ]; } 

screenshot of yii2 log. updated

yiilog

inspect element screenshot html

thanks!!!

add 'enctype' => 'multipart/form-data' in activeform.

<?php $form = activeform::begin([     'options' => [         'enctype' => 'multipart/form-data',          'id' => 'dynamic-form'     ] ]); ?> 

set ajax validation false if don't want ajax validation.

reference


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -