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

設(shè)置未選中復選框php的值

Setting value of unchecked checkbox php(設(shè)置未選中復選框php的值)
本文介紹了設(shè)置未選中復選框php的值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有這個表格

<tr>
    <td>
        <input type="hidden" name="po[]" value="<?php echo $ord['id'] ?>" />
        <input type="hidden" name="acts[]" value="1" />
        <input id="acts" value='2' type="checkbox" <?php echo $check ?> name="acts[]" />
    </td>
    <td><img src="<?php echo $pnme['icon'] ?>" style="height: 25px; width: 25px; vertical-align: middle;" /><?php echo $pnme['name'] ?></td>
    <td><input id="per" style="background: #BDBDBD; width: 100px;" name="per[]" size="5" type="text" class="small" value="<?php echo $ord['fee'] ?>" /></td>
    <td><input id="dol" style="background: #BDBDBD; width: 100px;" name="dol[]" size="5" type="text" class="small" value="<?php echo $ord['cost'] ?>" /></td>
</tr>

如果未選中復選框,我試圖讓它傳遞不同的值,我有一個 hidden 輸入,但它沒有在我需要的地方正確傳遞值,當表單帖子這就是我處理信息的方式

I am trying to get it to pass a different value if the checkbox is not checked, I have a hidden input but it does not pass the values correctly where I need it to, when the form posts this is how I handle the information

    $po = implode(",", $_POST['po']);
    $po = explode(",", $po);

    $fee = implode(",", $_POST['per']);
    $fee = explode(",", $fee);

    $co = implode(",", $_POST['dol']);
    $co = explode(",", $co);

    $act = implode(",", $_POST['acts']);
    $act = explode(",", $act);
    print_r($act);
    for ($i = 0; ; $i++) {
    if ($i > count($po) - 1) {
        break;
    }

例如,如果我檢查每個框,它會像這樣設(shè)置數(shù)組

for example if I check every box it sets the array like this

Array ( [0] => 1 [1] => 2 [2] => 1 [3] => 2 [4] => 1 [5] => 2 [6] => 1 [7] => 2 [8] => 1 [9] => 2 [10] => 1 [11] => 2 [12] => 1 [13] => 2 [14] => 1 [15] => 2 [16] => 1 [17] => 2 [18] => 1 [19] => 2 [20] => 1 [21] => 2 ) 

即使任何一個都應該有 2 的值

even though ever single one should have the value of 2

我添加了這個試圖將初始值設(shè)置為 1 認為如果選中該框它將覆蓋該值,但情況似乎并非如此

I added this trying to set the initial value to 1 thinking that if the box is checked it would overwrite the value, but this doesn't seem to be the case

我不確定如何處理這種情況并使其與我的處理代碼一起工作.

I am not sure how to handle this situation and make it work with my processing code.

推薦答案

[] 數(shù)組約定動態(tài)創(chuàng)建下一個索引,所以如果你有:

The [] array convention dynamically creates the next index, so if you have:

name="acts[]"
name="acts[]"

然后你得到:

acts[0]
acts[1]

需要保存checked和unchecked值的同名隱藏和checkbox輸入需要有相同的索引,所以指定如下:

The hidden and checkbox inputs with the same name that need to hold the checked and unchecked value need to have the same index, so specify like:

<input type="hidden" name="acts[0]" value="1" />
<input type="checkbox" name="acts[0]" value="2" />

<!-- more checkboxes -->

<input type="hidden" name="acts[10]" value="1" />
<input type="checkbox" name="acts[10]" value="2" />

這將為您提供一個 $_POST['acts'] 數(shù)組,其中包含 11 個項目,索引 0-10,值為 12取決于它是否被檢查.

This will give you a $_POST['acts'] array with 11 items, index 0-10 with the value either 1 or 2 depending on whether it was checked or not.

另外,我不知道你在用 implode()explode() 做什么.如果您只是想重新索引數(shù)字鍵,請使用 array_values($_POST['acts']).

Also, I have no idea what you are doing with the implode() and explode(). If you are just trying to reindex the numeric keys then use array_values($_POST['acts']).

這篇關(guān)于設(shè)置未選中復選框php的值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
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 簡單產(chǎn)品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 国产极品车模吞精高潮呻吟 | 国产欧美一区二区三区在线看 | 亚洲视频二区 | 黄色一级大片在线免费看产 | 91精品国产91久久久久游泳池 | 国产区免费视频 | 精品久久久久久18免费网站 | 午夜精品一区二区三区在线观看 | 夜夜爆操 | 日日操夜夜操天天操 | 国产一级黄色网 | 九九视频在线观看 | 亚洲精品免费在线观看 | 怡红院怡春院一级毛片 | 五月婷婷色 | 99亚洲综合 | 国产精品日韩欧美一区二区 | 亚洲网站在线观看 | 国产不卡一区 | 成年网站在线观看 | 亚洲精品国产成人 | 亚洲一区播放 | 午夜电影日韩 | 中文字幕日韩三级 | 欧美中文字幕 | 夜夜骑首页 | 成人在线亚洲 | 日韩一区二区三区四区五区 | 亚洲国产午夜 | 国产日韩欧美91 | 国际精品鲁一鲁一区二区小说 | 久久免费视频在线 | 狠狠干美女 | 日韩三级| 日韩久久精品电影 | 毛片一级片 | 色影视| 粉色午夜视频 | 国产一区 | 岛国精品 | 国产一区二区三区在线 |