2016-12-25 32 views
1

我有这种形式发送查询到同一页面

<form action="index.php?store=<?php echo $_GET['store'];?>/" method="GET"> 
     <input type="text" class="form-control txt-fc" name="s" placeholder="Enter Product Name" /> 
</form> 

当前页面的URL是这样

index.php?store=gsStore 

现在的问题是,当我提交表单的URL变成这样

index.php?s=Graphics+Cards 

由于在URL中有store因此PHP显示错误!我真正想要的是,它应提交表单不失store变量这样

index.php?store=gsStore&s=Graphics+Cards 

它是如何是可以实现的?

回答

3

使用隐藏的输入元素:

<form action="" method="GET"> 
    <input type="hidden" name="store" value="<?php echo $_GET['store'];?>"> 
    <input type="text" class="form-control txt-fc" name="s" placeholder="Enter Product Name" /> 
</form> 
+0

要老实跟你说......我用这一招使用'hidden'场了很多次......这一次没来了我的心。谢谢你的答案:)将接受无损时间罚款完成 –

+0

你应该考虑转义任何不需要的HTML标记,以避免GET漏洞。 –

+0

@AlexShifu如果用户关注没有存储参数的链接,会发生什么情况?我认为你应该在PHP中处理它,并将用户重定向到默认存储区,或者在代码中放置默认存储区参数而不是GET ['store'](如果它为空)。想想看。 很高兴听到它有帮助。 – smozgur

相关问题