非表示の入力フィールドが表示されています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でそれを行うにはどうすればよいですか?