0

非表示の入力フィールドが表示されていますActiveForm

<?php $form = ActiveForm::begin(); ?>

    <input type="file" id="i_file" name="uploadfile" value="" onchange="abc()"> 
    <?= $form->field($model, 'path')->hiddenInput() ?>
    <div class="form-group">
        <?= Html::submitButton('submit', ['class' => 'btn btn-primary']) ?>
    </div>
<?php ActiveForm::end(); ?>

以下に示すように、Javascriptを使用して値を設定しています。

<script>
function abc(){
    var tmppath = URL.createObjectURL(event.target.files[0]);
    $("#taskreports-path").val(tmppath);

alert(document.getElementById("taskreports-path").value);
}   
</script>

アラートは、値がフィールドに正常に設定されたことを示します。今、私はその入力フィールドの値を次のようなphp変数に入れたいと思っています:

$var path = //<?= $form->field($model, 'path')->hiddenInput() ?> this field's value

Yii2でそれを行うにはどうすればよいですか?

4

2 に答える 2

0

コントローラー アクションの関数では、この方法で非表示の入力の値を取得できます。

$post = Yii::$app->request->post();
$var = $post[$model->formName()]['path'];
于 2016-01-11T13:49:16.427 に答える