基于PHP表单重定向的下拉选择 [英] PHP Form Redirect Based Off of Drop Down Selection
问题描述
这涉及到我曾询问过的一个问题。填写完表格后,我想确定在填写表单时通过选择的下拉列表提交表单后,它将转到哪个页面。
例如,你输入:
你的名字
电子邮件
电话号码
然后从下拉菜单中选择第3页。提交。
然后我需要它将您重定向到Page 3,因为这是您在下拉菜单中选择的那个。我知道这应该很简单,我似乎无法弄清楚如何去做。
在表单提交的脚本中:
if($ _POST ['dropdown-name'] =='Page 3'){
header(Location:page3.php);
header其他if($ _POST ['dropdown-name'] ==''Page 4'){
header(Location:page4.php);
} // ... etc
〜
$ pages = array('Page 1'=>'page1.php','Page 2'=>'page2.php','Page 3' =>'page3.php');
$ b $ if(array_key_exists($ _ POST ['dropdown-name'],$ pages)){
header(Location:。$ pages [$ _ POST ['dropdown-name']] ]);
} else {
echoError processing form; //提交的表单值不在你的数组中,也许是一个黑客攻击尝试
}
This relates to a previous question I had asked about filling out a php form and using those answers to populate a page. When finished filling out the form, I want to determine what page it goes to after you submit the form by a dropdown you choose while filling out the form.
For example, you type in:
Your Name
Phone Number
Then from a drop down you'd pick "Page 3".
Then hit submit.
I would need it then to redirect you to "Page 3" because that's the one you chose in the drop down. I know this should be simple, I just can't seem to figure out how to do it. Thank you in advance to all that help!
In the script your form submits to:
if ($_POST['dropdown-name'] == 'Page 3') {
header("Location: page3.php");
} else if ($_POST['dropdown-name'] == 'Page 4') {
header("Location: page4.php");
} // ... etc
~
$pages = array('Page 1' => 'page1.php', 'Page 2' => 'page2.php', 'Page 3' => 'page3.php');
if (array_key_exists($_POST['dropdown-name'], $pages)) {
header("Location: " . $pages[$_POST['dropdown-name']]);
} else {
echo "Error processing form"; // submitted form value wasn't in your array, perhaps a hack attempt
}
这篇关于基于PHP表单重定向的下拉选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!