大家好!
如何根据选中的复选框将表单提交到不同的 URL。我设法实现了这一点,只有 1 个复选框。但是,如果您添加第二个 该 php 不能识别传入的数据,因为它应该。
任务: 如何根据按钮复选框的选中组合重定向到 4 个不同的 URL。
- 使用复选框 1 发送到 1 个 URL
- 使用复选框 2 发送到 2 个 URL
- 使用复选框 1 和 2 发送到 3 个 URL
- 发送到 4 个 URL 而不取消 复选框
HTML
<form class="form-horizontal" action="http://URL/bamp/bump1.php" method="post">
<fieldset>
<!-- Form Name -->
<legend>PARAMETR</legend>
<!-- Multiple Checkboxes -->
<div class="form-group">
<label class="col-md-4 control-label" for="checkboxes">form</label>
<div class="col-md-4">
<!-- CHECK-BOX1 -->
<div class="checkbox">
<label for="checkboxes1">
<input type="checkbox" name="checkboxes1" id="checkboxes1" value="1">
checkboxes1
</label>
</div>
<!-- CHECK-BOX2 -->
<div class="checkbox">
<label for="checkboxes2">
<input type="checkbox" name="checkboxes2" id="checkboxes2" value="2">
checkboxes2
</label>
</div>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="singlebutton"> </label>
<div class="col-md-4">
<button id="singlebutton" name="singlebutton" class="btn btn-primary">START!</button>
</div>
</div>
</fieldset>
</form>
PHP 这是我的 PHP 文件,它采用这种形式用于以后的重定向。
if($_POST['checkboxes1'] == 1 ){
header("Location: http://URL/index1.html");
}
if($_POST['checkboxes2'] == 2){
header("Location: http://URL/index2.html");
}
else {
header("Location: http://URL/index3.html");
}
?>
Заранее спасибо за любую помощь и подсказки.
但是 if 中的诸如此类的东西暗示,一般来说,要解决您的问题,您应该寻找更优雅的解决方案。