kartik-v / yii2-widgets

Collection of useful widgets for Yii Framework 2.0
http://demos.krajee.com/widgets
Other
558 stars 175 forks source link

Sending empty file on Yii2 activeform #337

Closed alvarolordelo closed 6 years ago

alvarolordelo commented 7 years ago

Hi guys great work on this widget, but I'm facing some trouble here since the widget isn't sending the image selected. here is my form action <?php $form = ActiveForm::begin([ 'method' => 'post', 'action' => ['institucional/cadastrar-assinatura']], ['options' => ['enctype' => 'multipart/form-data']]); ?>

<?= $form->errorSummary($model); ?>

<?php
echo
$form->field($model, 'file')->label('Assinatura')->widget(FileInput::classname(), [
    'options' => ['accept' => 'image/*'],
    'pluginOptions' => [
        'showUpload' => false,
        'browseClass' => 'btn btn-primary btn-block',
        'browseIcon' => '<i class="glyphicon glyphicon-camera"></i> ',
        'browseLabel' => 'Selecione a Imagem'
    ],
]);
?>

<?= $form->field($model, 'image_title')->dropDownList(['0' => 'Diretor(a)']) ?>

<?=
$form->field($model, 'institucional_id')->dropDownList(
        ArrayHelper::map(Institucional::find()->orderBy('fantasy_name')->asArray()->all(), 'id', 'fantasy_name'), [
    'options' => [
        'placeholder' => 'Choose Institucional'
    ],
]);
?>
<div class="form-group">
    <?= Html::submitButton('Salvar', ['class' => 'btn btn-success btn-lg']); ?>
</div>

<?php ActiveForm::end(); ?>

My view import use kartik\widgets\FileInput; On my controller I've made some debug

if ($model->load(Yii::$app->request->post())) {

        $test = UploadedFile::getInstance($model, 'file');
        return var_dump($teste,Yii::$app->request->post(), $model, $_FILES);

// return $this->redirect(['index']); } else { return $this->render('create-assinatura', [ 'model' => $model, ]); }

kartik-v commented 6 years ago

Set your attribute file to safe in your Yii2 model validation rules.