用一个按钮提交循环生成的多个表单

Sorry for spaghetti code :( I can't figure out why is it not working. Button submits only last form, but i want to submit every generated form. What can i do? I tried AJAX but it gives the same result. I wanted to recursively add selections but i think it's the hardest way and there is another solution.

 <table id="datatable" class="table table-striped table-bordered">
   <thead>
    <tr>
     <th>Product Name</th>
     <th>Product Weight</th>
     <th>Product Image</th>
     <th>Status</th>
     <th>Choose suplier</th>
     <th>Delete</th>
    </tr>
   </thead>
   <tbody>
   <?php        
   foreach ($result as $k=>$v)
   {
      $oid[] = $v['op_id'];
      $pui[] = $v['pui'];
      ?>
      <tr>
       <td><?php echo substr($v['name'], 0,10); ?></td>
       <td><?php echo substr($v['gram'], 0,10); ?></td>
       <td><img style="width: 50%" src="<?php echo $site_url.'images/'.$v['image']; ?>" alt=""></td>
       <td><?php echo substr($v['opia'], 0,10); ?></td>
       <td>
          <form method="POST" enctype="multipart/form-data" id="demo-form2" data-parsley-validate oidd="<?php echo $v['pui']; ?>" class="form-horizontal form-label-left sels<?php echo $v['op_id'];?>">
           <div class="form-group">
             <label class="">
             </label>
           <div class="" style="width: 100%">
           <?php
            $sups = $db->prepare('SELECT * FROM product p, suplier s, prod_suplier ps WHERE p.u_id=ps.p_id AND ps.suplier_id=s.id AND p.u_id=:u_id GROUP BY s.id');
            $sups->execute(array('u_id'=>$v['pui']));
            $count_sups = $sups->rowCount();
            if ($count_sups==1) {
              $get_sups = $sups->fetch(PDO::FETCH_ASSOC);
              echo $get_sups['full_name'];
            } else {
            ?>
              <select style="" name="supliers" id="">
               <?php
                while ($get_sup=$sups->fetch(PDO::FETCH_ASSOC)) {
                ?>
                 <option value="<?php echo $v['sfn']; ?>"><?php echo $get_sup['full_name']; ?></option>
          <?php }?>
              </select>
      <?php } ?>
           </div>
         </div>
       </form>
      </td>
      <td>
       <form style=" float: right;" method="POST" action="<?php echo $site_url.$state.'delete/' ?>">
       <input type="hidden" name="delid" value="<?php echo $v['oid'] ?>">
       <button type="button" onclick="dsomo(this);" name="dbtn" style="color: red; background-color: rgba(0,0,0,0); border:none;" href="">
       <i class="fa fa-trash fa-2x" ></i>
       </button>
       </form>
      </td>
     </tr>
<?php }?>
    </tbody>
   </table>
  </div>
 </div>
</div>
<button type="submit" id="acception" name="submit">submit</button>
<script async>
$('#acception').on('click', function () {
<?php
for ($i=0;$i<count($oid);$i++) {
?>
  $("tr>td>.sels<?php echo $oid[$i];?>").submit();
<?php } ?>
})
</script>
查看全部
douhoulei4706
douhoulei4706
2019/03/04 08:13
  • php
  • html
  • javascript
  • forms
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复