簡體   English   中英

表單不提交或按鈕提交不起作用

[英]Form does not submit or button submit not working

據我所知,此代碼必須有效,但是我編碼時卻無效
問題在於該表單未提交。 我該如何解決?
選中時,我什至沒有得到復選框的值。

<table id="example" class="display" cellspacing="0" width="100%">
<thead>
    <th>ID</th>
    <th>Item Photo</th>
    <th>Item Name</th>
    <th>Stocks</th>
    <th>Date Posted</th>
    <th>Price</th>
    <th>Actions</th>
</thead>
<tbody>

<form action ="<?php echo base_url()?>Shop/test" method="POST">
    <?php
    $x=1;

    foreach($shop_items as $key)
    {
    ?>

    <tr>
        <td><input class="checkbox"  type="checkbox" name="cb[]" value="<?php $key->shop_item_id?>"> <?php echo $x;?> </td>
        <td><center><img src="<?php echo base_url()?>uploads/items_main/<?php echo $key->shop_item_main_pic;?>"  style = "width:60px;height:50px;"alt=""></center></td>
        <td><?php echo mb_strimwidth($key->shop_item_name, 0, 18,"...");?></td>
        <td style="width:10px;"><center><button><span class="fa fa-eye"></span></button></center></td>
        <td><?php echo date('F,d,Y',strtotime($key->shop_item_date_posted))?></td>
        <td><?php if(!$key->shop_item_sale){ echo number_format($key->shop_item_orig_price);}
        else{ echo "<font color='red'>".number_format(intval($key->shop_item_orig_price-($key->shop_item_orig_price*($key->shop_item_sale/100))))."</font> ";}?></td>
        <td>
            <a href="">Bid </a> | <a href=""> View</a>
        </td>
    </tr>
    <?php
        $x+=1; 
    }
    ?>
<button class='btn btn-danger btn-xs' type="submit" name="delete" value="delete"><span class="fa fa-times"></span> delete</button>

</form>
</tbody>

在Controller中,結構是這樣的

if(isset($_POST['delete']))
{
  if (isset($_POST["cb"])) {
     // Checkbox is checked.
  $cb = $_POST["cb"];
  echo $cb;
} 
else {
     $cb = $_POST["cb"];
     echo $cb;
}
        }

如果發出所有PHP,將留下錯誤的HTML:

    <table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <th>ID</th>
        </thead>
        <tbody>
            <form action="<?php echo base_url() ?>Shop/test" method="POST">
                <tr>
                    <td>
                        <input class="checkbox" type="checkbox" name="cb[]" value="<?php $key->shop_item_id ?>"> <?php echo $x; ?>
                    </td>
                </tr>
                <button class='btn btn-danger btn-xs' type="submit" name="delete" value="delete">
                    <span class="fa fa-times"></span> delete
                </button>
            </form>
        </tbody>
    </table>

form建議立即進行刪除不會是一個孩子tbody table任何內容都應在thtd標簽內。 你應該把form的外部tablebutton里面td標簽:

   <form action="<?php echo base_url() ?>Shop/test" method="POST">
        <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
                <th>ID</th>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <input class="checkbox" type="checkbox" name="cb[]" value="<?php $key->shop_item_id ?>"> <?php echo $x; ?>
                    </td>
                </tr>
                <tr>
                    <td>
                        <button class='btn btn-danger btn-xs' type="submit" name="delete" value="delete">
                            <span class="fa fa-times"></span> delete
                        </button>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM