我有4个单选按钮的表单 1)seth 2)罗马 3)院长 4)其它
如果用户点击其他人,则会打开一个文本框,用户输入自己的姓名
在php中,我希望从用户选择的3个选项中选择任一形式,或者从文本框中选择
if(isset($_POST['btnsave']))
{
$event = trim($_POST['event']);
$other_event = trim($_POST['other_event']);
$date = date("Y-m-d", strtotime($_POST['date']));
$info = trim($_POST['notes']);
$upd_date = date('Y-m-d H:i:s');//upl_date
$ucode = md5(uniqid(rand()));
if(empty($event) || ($other_event =='others' && empty($other_event)))
{
$errMSG = "Please enter camera name";
}
else
{
$event_name = ($event =='others') ? $other_event : $event;
echo $event_name;
}
}
>
我的表格:
<div class="form-group">
<label class="control-label col-sm-3">Meal Preference</label>
<div class="col-sm-9">
<div class="checkbox">
<label>
<input type="radio" id="calorieCheckbox" name="event" value="VIRINCHI" style="margin-right: 8px;">seth
</label>
</div>
<div class="checkbox">
<label>
<input type="radio" id="saltCheckbox1" name="event" value="JOB_MELA " style="margin-right: 8px;">roman
</label>
</div>
<div class="checkbox">
<label>
<input type="radio" id="saltCheckbox2" name="event" value="MOCK_INTERVIEW" style="margin-right: 8px;"> dean
</label>
</div>
<div class="checkbox">
<label style="padding-bottom: 12px;">
<input type="radio" id="saltCheckbox3" onclick="ShowHideDiv()" value="others" style="margin-right: 8px;">others
</label>
</div>
<div class="col-sm-9" style="display: none;" id="others">
<input type="text" id="email" placeholder="Event type" name="other_event" class="form-control">
</div>
</div>
</div>
答案 0 :(得分:3)
您错过了name="event"
广播中的value="others"
attr。
和
if(empty($event) || ($other_event =='others' && empty($other_event)))
应该是
if(empty($event) || ($event =='others' && empty($other_event)))