2 回答

TA貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊
您的表單有一個(gè)選擇輸入并設(shè)置為使用POST. 當(dāng)它提交時(shí),PHP 會(huì)顯示你在值中選擇了什么 $_POST["Country"]
您的第一個(gè)選項(xiàng)缺少一個(gè)值 - 所以如果提交了它,它可能不會(huì)顯示為好像他們回答了它。我建議添加,value=""以便它將在 中POST,您可以驗(yàn)證是否選擇了一個(gè)選項(xiàng)。此外,您需要一個(gè)提交按鈕。
<form action="/select_country" method="post" >
<select name="Country" class="country-selection">
<option value="" required="" selected="" disabled="" style="color: #b5b5be;">Country Location</option>
<option value="1" >Asia</option>
<option value="2" >Australia</option>
<option value="3" >United States</option>
<option value="4" >Europe</option>
</select>
<input type="submit">
</form>
然后:
<?php
if (isset($_POST["Country"]) {
if ($_POST["Country"] == "") {
// error you must select an option
}
//other validation here but this should be 1,2,3 or 4
// keep in mind anyone can mess with the form and submit other things maliciously so do validate
}

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
您應(yīng)該使用,$_POST["Your Input item Name Here"]因?yàn)槟谋韱问褂玫氖荘OSTmethod 而不是GET.
保持 Html 不變,請(qǐng)嘗試以下操作:
//your name attribute = "Country" for select element
if (isset($_POST["Country"])) {
return $_POST["Country"];
}
- 2 回答
- 0 關(guān)注
- 209 瀏覽
添加回答
舉報(bào)