在动态表中显示信息以及附件名称

鲁比尼·埃里克(Rupiny Eric)
    <div>

嗨,大家好,我的桌子可以让我输入汽车信息,还可以附上他们的卡的副本。然后,我可以通过单击“添加数据”按钮添加另一行来添加另一行。这里的问题是,当我提交信息时,仅会显示第一辆汽车的信息及其上载的卡,而对于第二辆汽车,则只会显示卡名。

<!---/ html table /--->
    <table class="" id="tab_logic1">            
                                    <thead>
                                        <tr class="success">
                                            <th colspan="6">SECTION 4: LIST OF VEHICLES <small><i>(Please list down vehicles registered in company names. Attach vehicle registration card)</i></small></th>
                                        </tr>

                                        <tr>
                                            <th>#</th>                                                  
                                            <th class="text-center">Registration Number</th>
                                            <th class="text-center" >Make</th>
                                            <th class="text-center" >Type</th>
                                            <th class="text-center" >Capacity</th>
                                            <th class="text-center" >Attach</th>

                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr id='addrw0'>
                                            <td>1</td>
                                            <td><input type="text"  class="form-control" name='registrationNumber[]'  ></td>
                                            <td><input type="text"  class="form-control" name='vehicleMake[]'  ></td>
                                            <td><input type="text"  class="form-control" name='vehicleType[]'  ></td>
                                            <td><input type="text"  class="form-control" name='VehicleCapacity[]' ></td>
                                            <td  class="text-center"><input type="file" name="files[]"   class="btn btn-sm btn-primary"></td>
                                        </tr>
                                        <tr id='addrw1'></tr>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <th colspan='6'>
                                                <a id="add_new_row" data-placement="right" class="btn btn-info pull-left" data-toggle="tooltip" title="Add another vehicle">Add Data</a>
                                                <a id="delete_new_row" data-placement="left" class="pull-right btn btn-info" data-toggle="tooltip" title="Remove vehicle">Delete Data</a>

                                            </th>
                                        </tr>

                                    </tfoot>

                                </table>
<!--jquery for adding rows-->

            $(document).ready(function(){
                var i=1;
                $("#add_new_row").click(function(){
                    $('#addrw'+i).html("<td>"+ (i+1) +"</td><td><input type='text'  name='registrationNumber[]"+i+
                    "' class='form-control' required></td><td><input type='text'  name='vehicleMake[]"+i+
                    "' class='form-control' required></td><td><input type='text'  name='vehicleType[]"+i+
                    "' class='form-control' required></td><td><input type='text'  name='VehicleCapacity[]"+i+
                    "' class='form-control' required></td><td><input type='file'  name='files[]"+i+
                    "' class='btn btn-sm btn-primary' required></td>");

                    $('#tab_logic1').append('<tr id="addrw'+(i+1)+'"></tr>');
                    i++; 
                });
                $("#delete_new_row").click(function(){
                    if(i>1){
                        $("#addrw"+(i-1)).html('');
                        i--;
                    }
                });

            });

<!---displaying each row information with its attachment-->
<?php
            $errors                   = array();

                $messages                 = array();
            if (isset($_POST["submitbtn"])) {


                $registrationNumber  = count($_POST["registrationNumber"]);

                $vehicleMake = $_POST["vehicleMake"];

                $vehicleType =  $_POST["vehicleType"];

                $VehicleCapacity =  $_POST["VehicleCapacity"];

                //  $file_name  =   $_FILES['files']['names'];



                for($x=0;$x<$registrationNumber;$x++) {

                    $file_name      =   $_FILES['files']['name'][$x];
                    $file_size      =   $_FILES['files']['size'][$x];
                    $file_type      =   $_FILES['files']['type'][$x];   
                    $file_tmp       =   $_FILES['files']['tmp_name'][$x];

                    $messages[] = "Your car is ".$_POST["vehicleMake"][$x]." and card is ".$file_name;



                }
/*displaying message*/

    if (isset($messages)) {
                    foreach ($messages as $message) {
                        echo '<div class="alert alert-success text-center" style="font-size: 14px;font-weight:bold;" role="alert">'.$message.'</div>';
                    }
                }
?>

约翰·洛克

您不需要将索引放入标记中。

删除标记中的索引将解决您的问题,例如

$("#add_new_row").click(function(){
            $('#addrw'+i).html("<td>"+ (i+1) +"</td><td><input type='text'  name='registrationNumber[]' class='form-control' required></td><td><input type='text'  name='vehicleMake[]' class='form-control' required></td><td><input type='text'  name='vehicleType[]' class='form-control' required></td><td><input type='text'  name='VehicleCapacity[]' class='form-control' required></td><td><input type='file'  name='files[]' class='btn btn-sm btn-primary' required></td>");

            $('#tab_logic1').append('<tr id="addrw'+(i+1)+'"></tr>');
            i++; 
        });

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章