[英]PHP Sessions + Radio buttons to link to a specific form
首先是我的 PHP 代码
if(!isset($_POST['selection'])){
$missing['selection'] = $required['selection'];
}
if(empty($missing)) {
post2session();
$_SESSION['step'][0] = 0;
redirect("");
}
这是我的 HTML
<form action="" method="post">
<table cellpadding="0" cellspacing="0" border="0" class="tbl_insert">
<tr>
<th><label for="selection">Select from following that applies to you</label></th>
<td>
<input type="radio" name="selection" id="selection" group="form_type" value="form1"> />Form 1<br />
<input type="radio" name="selection" id="selection" group="form_type" value="form2" />Form 2<br />
<input type="radio" name="selection" id="selection" group="form_type" value="form3" />Form 3<br />
<input type="radio" name="selection" id="selection" group="form_type" value="form4" />Form 4<br />
</td>
</tr>
</table>
</form>
如果他们选择无线电“form1”,我将如何将用户重定向到 FORM1; FORM2 如果他们选择了“form2”; 等等
感谢您提供的帮助 (Y)
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
switch($_POST['selection']) {
case 'form1': $url = '/wherever/form1/is'; break;
case 'form2': $url = '/wherever/this/other/form/goes'; break;
...
default: $url = '/some/default/handler';
}
redirect($url);
}
重定向到新页面通常是这样完成的:
header('Location: www.site.tld/anotherpage.php');
exit();
首先将 name 属性转换为数组name="selection[]"
dio
并且不要对每个单选按钮使用相同的 id,或者您 r 能够同时检查所有单选按钮,因为php使用name
和javascript使用id
并在帖子页面上尝试通过print_r($_POST['name'])
检查
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.