【发布时间】:2018-09-17 03:56:02
【问题描述】:
我的 HTML 端有这样的表单:
<form method="post">
<div class="radio">
<label><input type="radio" class="optradio" name="optMsg" value="user is no longer exist">user is no longer exist.</label>
</div>
<div class="radio radioOthersHolder">
<label><input type="radio" class="radioOthers optradio" name="optMsg" value="0">others</label>
</div>
<button type="submit" name="delete" class="btn btn-danger margin-top">
Submit
</button>
</form>
这就是我根据单选选择附加输入控件的方式:
$(document).ready(function(){
$('.optradio').change(function(){
if($('.radioOthers').is(':checked')) {
$('.radioOthersHolder').append('<input type="text" name="txtOthers" class="form-control txtOthers" max="160" placeholder="State your message here." required />');
} else {
$('.txtOthers').remove();
}
});
});
然后在我的 PHP 端,我尝试获取所有 POST 数据并检查值,但如果我选择其他单选并提交,我的附加输入似乎无法识别。我不确定它会导致什么。
if(isset($_POST['delete'])){
if(isset($_POST['optMsg']) && !empty($_POST['optMsg'])){
if($_POST['optMsg'] == 0){
if(isset($_POST['txtOthers']) && !empty($_POST['txtOthers'])){
$reasonMsg = $_POST['txtOthers'];
}
} else {
$reasonMsg = $_POST['optMsg'];
}
print_r($_POST); exit();
}
}
【问题讨论】:
标签: php post input append codeigniter-3