将表单发布到自我时如何保留GET参数? [英] How to preserve GET parameters when posting form to self?

查看:126
本文介绍了将表单发布到自我时如何保留GET参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GET参数的URL。我试图发布一个简单的表单,基本上简单地添加一个GET参数到URL。



当前网址:mysite.com/page.php?first=123

表格HTML:

 <?php $ first = $ _GET [ '第一']; ?> 

< form method =getaction =page.php?first =<?php echo $ first;?>>
< input type =textname =second>< br>
< input type =submitvalue =Submit>< br>
< / form>

我试图让网址为:mysite.com/page.php?first= 123& second = 456



但是,在提交表单时,页面URL会丢弃第一个GET参数并更改为:mysite.com/page.php?second=456



如何在第一个已经存在的GET参数之后提交此表单并添加第二个GET参数以添加到URL的末尾?



谢谢

解决方案

您需要使用隐藏输入:

 < input type =hiddenname =firstvalue =<?php echo htmlspecialchars($ first,ENT_QUOTES);?> /> 


I have a URL with one GET parameter. I am trying to post a simple form, basically to simply add one more GET parameter to the URL.

Current URL: mysite.com/page.php?first=123

Form HTML:

<?php $first = $_GET['first']; ?>

<form method="get" action="page.php?first=<?php echo $first; ?>">
<input type="text" name="second"><br>
<input type="submit" value="Submit"><br>
</form>

I'm trying to get the URL to be: mysite.com/page.php?first=123&second=456

However, when submitting the form, the page URL drops the first GET parameter and changes to: mysite.com/page.php?second=456

How can I submit this form and add the second GET parameter to add onto the end of the URL after the first already existing GET parameter?

Thanks

解决方案

You need to use hidden input instead:

<input type="hidden" name="first" value="<?php echo htmlspecialchars($first, ENT_QUOTES); ?>" />

这篇关于将表单发布到自我时如何保留GET参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆