开发者

HTML $_POST questions

I currently have a form and below the form, I have a checkbox and some radio buttons. Here is the code for the checkbox and radio buttons:

<li id="discountCheckbox"       class="     ">
    <label class="desc" id="title416" for="Field416">
        Discounts Available:
            </label>
    <div>
        <span>
    <input id="discountCheckbox"        name="discountCheckbox"         type="checkbox"         class="field checkbox"      value="Past Host Discount - 10%"        tabindex="12"                       />
    <label class="choice" for="Field416">Past Host Discount - 10%</label>
    </span>
        </div>
    </li>


<li id="shipping1"      class="     ">
<label class="desc" id="shippingChoice" name="shippingLabel" value="yahha" for="Field517_0">
    Shipping Options
        </label>
<div>
<input id="9281" name="9821" type="hidden" value="" />
    <span>
<input id="shipping1"       name="shipping1"        type="radio"        class="field radio"         value="cost"        tabindex="13"                        checked="checked"      onclick="setShippingSpan('$2.00');"             />
<label class="choice" for="Field517_0"      >
    $2.00 Shipping Fee</label>
    </span>
    <span>
<input 开发者_StackOverflow社区id="shipping2"       name="shipping1"        type="radio"        class="field radio"         value="free"        tabindex="14"           onclick="setShippingSpan('$0.00');"                 />
<label class="choice" for="Field517_1"      >
    I will pick up the items (free shipping)</label>
    </span>
    </div>
</li>

On submission of my form, I have a file process.php that is run. In that file, I grab the value of the checkbox using $_POST["discountCheckbox"]. But, I can't figure out how to grab the value of the radio buttons (determining which one is selected). How do I do this?


Give the radio buttons all the same name and then that name in your $_POST will have the value of the selected radio button.


Give the radio buttons the same name but different values. When the form is submitted look up the value which is selected by simply checking the value of that name in the $_POST array.


I believe your input elements of type radio should share a common name attribute and be distinguished by their value attributes. Then, in your PHP code, you'd check the value of $_POST[] indexed by the name, which should contain the value of the selected radio button.


By giving all radio buttons the same name you'll get the value of the selected one in the $_POST[name] variable.

<input name="shipping" value="something" type="radio" />

echo $_POST['shipping']; // echoes "something"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜