久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 php 檢測未選中的復選框?

How can I detect unchecked checkbox with php?(如何使用 php 檢測未選中的復選框?)
本文介紹了如何使用 php 檢測未選中的復選框?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我的表單中有 3 個(我不知道有多少是可以更改的.只有 3 個示例)復選框,我想在發布時使用 php 檢測未選中的復選框.我該怎么做?

There are 3(I do not know how many would be it changeable. 3 only example) checkboxes in my form and I want to detect unchecked checkboxes with php when it post. How can I do this?

推薦答案

秋葵湯是對的.但是,有一個解決方法,如下所示:

Gumbo is right. There is a work around however, and that is the following:

<form action="" method="post">
    <input type="hidden" name="checkbox" value="0">
    <input type="checkbox" name="checkbox" value="1">
    <input type="submit">
</form>

換句話說:有一個與復選框同名的隱藏字段和一個表示未選中狀態的值,例如 0.然而,重要的是讓隱藏字段位于表單中的復選框之前.否則,如果復選框被選中,隱藏字段的值將在發布到后端時覆蓋復選框值.

In other words: have a hidden field with the same name as the checkbox and a value that represents the unchecked state, 0 for instance. It is, however, important to have the hidden field precede the checkbox in the form. Otherwise the hidden field's value will override the checkbox value when posted to the backend, if the checkbox was checked.

另一種跟蹤此情況的方法是在后端有一個可能的復選框列表(例如,甚至可以在后端使用該列表填充表單).類似下面的內容應該會給你一個想法:

Another way to keep track of this is to have a list of possible checkboxes in the back-end (and even populate the form in the back-end with that list, for instance). Something like the following should give you an idea:

<?php

$checkboxes = array(
    array( 'label' => 'checkbox 1 label', 'unchecked' => '0', 'checked' => '1' ),
    array( 'label' => 'checkbox 2 label', 'unchecked' => '0', 'checked' => '1' ),
    array( 'label' => 'checkbox 3 label', 'unchecked' => '0', 'checked' => '1' )
);

if( strtolower( $_SERVER[ 'REQUEST_METHOD' ] ) == 'post' )
{
    foreach( $checkboxes as $key => $checkbox )
    {
        if( isset( $_POST[ 'checkbox' ][ $key ] ) && $_POST[ 'checkbox' ][ $key ] == $checkbox[ 'checked' ] )
        {
            echo $checkbox[ 'label' ] . ' is checked, so we use value: ' . $checkbox[ 'checked' ] . '<br>';
        }
        else
        {
            echo $checkbox[ 'label' ] . ' is not checked, so we use value: ' . $checkbox[ 'unchecked' ] . '<br>';
        }
    }
}
?>
<html>
<body>
<form action="" method="post">
    <?php foreach( $checkboxes as $key => $checkbox ): ?>
    <label><input type="checkbox" name="checkbox[<?php echo $key; ?>]" value="<?php echo $checkbox[ 'checked' ]; ?>"><?php echo $checkbox[ 'label' ]; ?></label><br>
    <?php endforeach; ?>
    <input type="submit">
</form>
</body>
</html>

...勾選一兩個復選框,然后點擊提交按鈕,看看會發生什么.

... check one or two checkboxes, then click the submit button and see what happens.

這篇關于如何使用 php 檢測未選中的復選框?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 亚洲精美视频 | 久久国产精品色av免费观看 | 蜜桃综合在线 | 久久精品免费观看 | 久视频在线观看 | 国产午夜精品久久久久 | 香蕉久久a毛片 | 欧区一欧区二欧区三免费 | 高清视频一区二区三区 | 美女国内精品自产拍在线播放 | 日本亚洲欧美 | 婷婷成人在线 | 日日干干 | 福利视频一区二区 | 91色视频在线 | 国产精品中文字幕在线观看 | 欧美一区二区三区视频 | 国产成人精品综合 | 国产高清久久 | 91av视频在线免费观看 | 午夜影院在线 | 免费在线看a | 毛片黄片免费看 | 久久99精品久久久久久国产越南 | 欧美成人猛片aaaaaaa | 91在线区| 狠狠干狠狠插 | 日本久久久一区二区三区 | 一级黄色生活视频 | 国产视频精品免费 | 国产三级日本三级 | 天天爱天天操 | 亚洲视频免费播放 | 欧美精品在线免费观看 | 久草中文在线 | 国产精品成人一区二区三区夜夜夜 | 亚洲大片一区 | 欧美一区二区三区在线看 | 成人99| 欧美一级二级视频 | 日韩国产欧美一区 |