Php 一个带有两个提交按钮的输入文本字段,用于搜索单独的页面
我有一个项目,需要一个搜索表单,根据用户的搜索内容搜索两个独立的易趣商店 我想有一个输入字段和两个提交按钮。我在获取表单以指定从任一按钮调用哪个站点时遇到问题。我已经仔细看了一下,尝试了一些方法,但认为有人可能会理顺我的语法等等 我有表格Php 一个带有两个提交按钮的输入文本字段,用于搜索单独的页面,php,url,isset,Php,Url,Isset,我有一个项目,需要一个搜索表单,根据用户的搜索内容搜索两个独立的易趣商店 我想有一个输入字段和两个提交按钮。我在获取表单以指定从任一按钮调用哪个站点时遇到问题。我已经仔细看了一下,尝试了一些方法,但认为有人可能会理顺我的语法等等 我有表格 <form target="_blank" action="rp.php" method="get"> <input type="text"> <button name="replacement" type="submit"&
<form target="_blank" action="rp.php" method="get">
<input type="text">
<button name="replacement" type="submit">Search Replacement Parts</button>
<button name="performance" type="submit">Search Performance Parts</button>
</form>
搜索替换零件
搜索性能部件
…我有PHP
<?php
if( isset($_GET['replacement']) ) {
header("Location: http://www.example.com");
exit;
} else if {
( isset($_GET['performance']) ) {
header("Location: http://www.example.com");
exit;
}
?>
我想我的思路是对的,只是需要一点帮助。我不知道是使用POST还是GET,GET对我来说似乎更有意义。您的PHP对于
其他版本来说有点不合适,否则它应该“工作”
您可以使用GET
或POST
来执行此操作,但是GET
将导致查询值在查询字符串中可见,并且在某些旧浏览器中大小有限POST
可能更受欢迎,在这种情况下,您可以将上面代码中的$\u GET
替换为$\u POST
,并将表单中的method=“GET”
更改为method=“POST”
。我会对两个按钮使用相同的名称,使用不同的值,然后在php代码中检查提交的值。您可以使用以下代码:
<form target="_blank" name="myform" method="POST">
<input type="text" name="search">
<button onclick="submit1('http://example1.com/')" >Search Replacement Parts</button>
<button onclick="submit1('http://example2.com/')" >Search Performance Parts</button>
</form>
<script>
function submit1(url)
{
document.myform.action=url;
document.myform.submit();
}
</script>
搜索替换零件
搜索性能部件
函数submit1(url)
{
document.myform.action=url;
document.myform.submit();
}
从您的问题很难猜出您的确切要求。您能进一步解释一下吗?不能使用POST。您的header()重定向将转换为GET请求,丢失POST表单数据。还需要将表单POST方法定义为POST
谢谢大家,Vikas/Peter-这对我的场景最有效,干杯。D
<form target="_blank" name="myform" method="POST">
<input type="text" name="search">
<button onclick="submit1('http://example1.com/')" >Search Replacement Parts</button>
<button onclick="submit1('http://example2.com/')" >Search Performance Parts</button>
</form>
<script>
function submit1(url)
{
document.myform.action=url;
document.myform.submit();
}
</script>