本文介绍了输入类型=“文件".发布时数据为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理车辆损坏"表格,用户可以在其中单击其车辆的图片.

I'm working on a Vehicle damage form where users can click picture of their vehicle.

它如何工作?

  1. 他们选择想要单击的照片的描述.
  2. 然后他们点击添加"按钮
  3. 我将输入类型文件作为子项添加到div(在form元素内部)中.

问题?

这些附加的输入类型文件不会将数据传递到下一页.

These appended input type files are not passing data to next page.

我尝试了什么?

我在html代码中添加了输入类型文件字段,它运行良好.我能够通过PHP在下一页上获取数据.但是,当我通过javascript添加相同的文件元素时,它没有传递数据.我的$ _FILES数组显示为空.

I added input type file field in my html code and it worked perfectly. I was able to get data on next page via PHP. But when I'm adding the same file element via javascript, it's not passing data. My $_FILES array shows empty.

HTML代码

<div class="meet-mainbody">

<form action="tst.php" method="POST" enctype="multipart/form-data">

<div class="row">
<div class="col-sm-6">
    <h3>Panel Damage</h3>
</div>
<div class="col-sm-3"><input type="radio" name="panel_damage" class="meet-checkbox" value="No" checked  onclick="shwPanelPhoto('panDamag', 'N')"/> NO</div>
<div class="col-sm-3"><input type="radio" name="panel_damage" class="meet-checkbox" value="Yes" onclick="shwPanelPhoto('panDamag', 'Y')"/> YES</div>
</div>
<br>
<div class="row hid_field" id="panDamag">
<div class="col-sm-6">
    <select name="panvalues" class="meet-select" id="panDamType">
        <option value="">Choose a Photo Description</option>
        <?php
            $getPanD = "SELECT S.OptionName, S.Active FROM table1 Q
                    LEFT JOIN table2 L on Q.QuestionID = L.QuestnID
                    LEFT join table3 S on L.OptionID = S.SelectID
                    WHERE Q.QuestionID = '15' and S.SelectType = 'AddedBox' and S.Active = 'true'";
            $getPanDPass = sqlsrv_query($conn, $getPanD, $params, $options);
            if($getPanDPass){
                while($PDrow = sqlsrv_fetch_array($getPanDPass, SQLSRV_FETCH_ASSOC)){
                    echo'<option value="'.$PDrow['OptionName'].'">'.$PDrow['OptionName'].'</option>';
                }
            }
            echo '</select>';
        ?>
    </select>
</div>
<div class="col-sm-6"><button type="button" class="panel-button" onclick="AddChooseFile('shwChoos')">ADD</button></div>
</div>
<br>

<div id="shwChoos"></div>
<br><br>
<!--- end code here---->
<center><input id="sub_btn" type="submit" class="meet-button meet-disabled " name="submit" value="Submit" disabled /></center>
</form>
</div>

这是我通过javacsript添加输入类型文件的代码

Here is the code where I'm adding input type file via javacsript

function AddChooseFile(opt){
    var typ = document.getElementById('panDamType').value;
    var par = document.getElementById('shwChoos');
    var cnt =  par.childElementCount;
    console.log('count is '+cnt);
    //create elements
    var elm1 = document.createElement('div');
    elm1.setAttribute('class', 'row');
    elm1.setAttribute('id', '');

    // elm1.innerHTML = '<div class="col-sm-4"><b>'+typ+'</b></div>'+
                    // '<div class="col-sm-4"><input type="file" name="mtu" accept="image/*" capture required ></div>'+
                    // '<div class="col-sm-4"><i class="fas fa-trash" onclick=""></i></div>';
    var elm2 = document.createElement('input');
    elm2.setAttribute('type', 'file');
    elm2.setAttribute('name', 'mtu');
    elm2.setAttribute('accept', 'image/*');


    elm1.appendChild(elm2);
    par.appendChild(elm1);
    par.appendChild(document.createElement('br'));


}

推荐答案

谢谢大家.但我找到了答案.表单标签放置在错误的位置.我将其移至主要div的顶部,然后开始工作.道歉

Thank you everyone. but I found the answer. The form tag was in the wrong place. I shifted it to the top of the main div and it started working. Apologies

这篇关于输入类型=“文件".发布时数据为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 18:18