1 回答

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
首先,用 去掉復(fù)選框value="0"。這并不像您期望的那樣工作。如果未選中復(fù)選框,則根本不會(huì)將其發(fā)送到服務(wù)器。這意味著如果它被選中,它將發(fā)送值0,因此它永遠(yuǎn)不會(huì)被正確設(shè)置。
接下來(lái),添加一個(gè)具有相同名稱和 的隱藏輸入value="0"。如果此輸入放置在復(fù)選框之前,則在未選中該復(fù)選框時(shí)會(huì)將其發(fā)送到服務(wù)器。如果選中該復(fù)選框,它將覆蓋此隱藏輸入。
//ternary - variable holds 'checked' if `$photo_private == 1`, or an empty string if not.
$is_checked = $photo_private == "1" ? 'checked' : '';
//hidden input - Submitted if checkbox is not checked.
echo '<input type="hidden" name="private_photo['.$photo_id.']" value="0">';
//checkbox - overwrites previous hidden input if checked.
//Utilizes `$is_checked` to check the checkbox by default when appropriate
echo '<input type="checkbox" name="private_photo['.$photo_id.']" value="1" '.$is_checked.'>';
這應(yīng)該有效,因?yàn)槿绻x中該復(fù)選框,它將覆蓋隱藏輸入中的值。如果未選中,則將提交隱藏的輸入值。
- 1 回答
- 0 關(guān)注
- 162 瀏覽
添加回答
舉報(bào)