2019-03-04 08:13
浏览 244


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">
     <th>Product Name</th>
     <th>Product Weight</th>
     <th>Product Image</th>
     <th>Choose suplier</th>
   foreach ($result as $k=>$v)
      $oid[] = $v['op_id'];
      $pui[] = $v['pui'];
       <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>
          <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="">
           <div class="" style="width: 100%">
            $sups = $db->prepare('SELECT * FROM product p, suplier s, prod_suplier ps WHERE p.u_id=ps.p_id AND AND p.u_id=:u_id GROUP BY');
            $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="">
                while ($get_sup=$sups->fetch(PDO::FETCH_ASSOC)) {
                 <option value="<?php echo $v['sfn']; ?>"><?php echo $get_sup['full_name']; ?></option>
          <?php }?>
      <?php } ?>
       <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>
<?php }?>
<button type="submit" id="acception" name="submit">submit</button>
<script async>
$('#acception').on('click', function () {
for ($i=0;$i<count($oid);$i++) {
  $("tr>td>.sels<?php echo $oid[$i];?>").submit();
<?php } ?>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongyi1429 2019-03-04 09:54

    Thanks to MojoAllmighty I found the solution. As described in the link below if I want to submit multiple forms by one button I have to assign equal classes to form and use ajax for async submitting forms. So maybe it can be marked as a duplicate of a link below.

    解决 无用
    打赏 举报

相关推荐 更多相似问题