我有一個困擾了我好幾天的問題 - 當複選框處於打開狀態或關閉狀態時,我試圖將一個變量添加到選項值中。變量顯示,但不是我想要的方式,當複選框關閉時,我希望「No Subscription」被添加到選項值中,當複選框打開時,「subscribe」被添加到選項值中。 這裏是我的腳本:PHP沒有選擇正確的複選框狀態來設置變量
<?php
if(isset($_POST['subscribe']) == '1') {
$sub = ", Subscribe";
} else {
$sub = ", No Subscription";}
?>
--------------------------------------------------------------------------------------------
<form class="cart" action="http://serber.com" method="post">
<section class="clear"></section>
<label>Tampons (Non-Applicator) Regular : </label>
<select name="productpr">
<option value="NT12<?php printf($sub); ?>:17.95">1 Month - $17.95 <span></span> </option>
<option value="NT12 3 Months<?php printf($sub); ?>:33.85">3 Months - $33.85</option>
<option value="NT12 6 Months<?php printf($sub); ?>:57.70">6 Months - $57.70</option>
</select>
<input type="hidden" name="submitted" value="true" />
<br /><input type="submit" value="Add to Cart">
<input type="hidden" name="subscribe[]" value="0" />
<input type="checkbox" name="subscribe[]" value="1">Check Box if you wish to have a recurring subscription</input>
</form>
I am at my wit's end with this because it seems I have the isset correct but the checkbox value
沒有被設置。如果
爲什麼使用複選框名稱作爲數組 –