您好,我的多步表单快要结束了,一切顺利 我已经用 php 和 javascript 验证了我的表单,但我现在需要的是当用户点击 我的表单中的一个 radio ,该 radio 值用于在提交我的表单后确定用户的目的地。
为了更清楚地说明,我希望当用户检查我的三个 radio 之一输入选中的输入 radio 时,在提交表单后将他带到所需的页面,在我的情况下是所需的 chekoutpage。 听到我的 radio 代码:
<div id="emotion" name="emotion1" >
<input type="radio" name="emotion" id="basi" value="Basic Pack" />
<label for="basi"><img src="images/basi.jpg" width="630px" alt="basi" /></label><br>
<input type="radio" name="emotion" id="deli" value="Deluxe Pack" />
<label for="deli"><img src="images/deli.jpg" width="630px" alt="deli" /></label><br>
<input type="radio" name="emotion" id="premi" value="Premium Pack"/>
<label for="premi"><img src="images/premi.jpg" width="630px" alt="premi" /></label>
</div><hr>
在 php 中,我有这段代码可以在提交 echo 标记后将用户带回表单:
if( $_POST['copy'] == 'on' )
{
mail($_POST['email'], $subject, $message, $headers);
} }
echo "<script>
alert('message sent succesfully');
window.history.go(-1);
</script>";
}
?>
为了让它更清楚我想要例如 radio1 radio2 radio3 如果选择了 radio1 而不是提交 html5 如果 radio2 比提交 html6 之后我希望我清楚 提前致谢
最佳答案
我认为 Ohgodwhy 指的是根据用户输入的内容进行条件/重定向:
$emotion = $_POST['emotion'];
if($emotion == 'Basic Pack') {
header('Location: html5.php');
} elseif($emotion == 'Deluxe Pack') {
header('Location: html6.php');
} elseif($emotion == 'Premium Pack') {
header('Location: html7.php');
}
// or by using switch() which ever you're comfortable with
旁注:顺便说一句,您不能将 alert()
与 PHP header 重定向一起使用。因为已经有输出了。
如果您不想保留 alert()
,不妨一直使用 javascript 重定向。
window.location = "http://www.yoururl.com";
关于javascript - 提交时如何使单选字段确定下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26091872/