我在html中添加了一个动态选择器,用于在注册时选择性别和国家/地区,现在的问题是我如何使用IF和Else短手来检查用户是否已选择两者以便注册完成,
这是我添加的选择
<div>Gender:</div>
<select id="gender" onfocus="emptyElement('status')">
<option value=""></option>
<option value="m">Male</option>
<option value="f">Female</option>
</select>
<div>Country:</div>
<select id="country" onfocus="emptyElement('status')">
<?php include_once("country_list.php"); ?>
</select>
<div>
答案 0 :(得分:0)
您必须在表单输入中添加name
属性。
<select id="gender" name="gender" onfocus="emptyElement('status')">
<select id="country" name="country" onfocus="emptyElement('status')">
然后您可以检查是否已设置。
if(!isset($_POST['gender']))
{
//Do what you need to if it is not set (such as a redirect)
}
if(!isset($_POST['country']))
{
//Do what you need to if it is not set (such as a redirect)
}
希望有所帮助。