php页面重定向取决于选择框的选择

标签 php javascript

我正在尝试重定向到一个页面,但基于选择框中的答案。基本上在下面的示例中,如果选择了 p1,如何让页面重定向到“thispage.php”,如果在通过按钮提交表单时选择了 p2,我如何才能重定向到“thatpage.php”?我感谢所有评论,谢谢。

<html> 
<body> 
<form name="form1"> 
<select name="select1"> 
<option value="p1">p1</option> 
<option value="p2">p2</option> 
<input type="submit"/>
</select> 
</form> 
</body> 
</html>

最佳答案

基本:

   <?PHP
    function redirect($where){      
       header("Location: $where");
    }
    if ($_REQUEST['select1'] == 'p1'){
        redirect('http://example.com/somewhere.php');
    }elseif($_REQUEST['select1'] == 'p2'){
        redirect('http://example.com/elsewhere.php');
    }

关于php页面重定向取决于选择框的选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3687976/

相关文章:

php - 仅替换文件形式 preg_replace 中的特定组

php - $wpdb 不工作,帖子中不显示任何内容

javascript - 如何随 promise 一起返回数据

javascript - Google Maps v3 API - 自动完成(地址)

javascript - 如何在 Edge 中下载图像/png 数据 URI?

javascript - 如何查找 HTMLElement 是否包含在所选文本中

JavaScript 计数数量

php - resource.create 和 resource.store 之间的 Laravel 区别

php - 在 div 中加载的页面的面包屑

php循环遍历多个数组