How to preserve GET parameters when posting form to self?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 15:22:37

问题


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


回答1:


You need to use hidden input instead:

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


来源:https://stackoverflow.com/questions/10524659/how-to-preserve-get-parameters-when-posting-form-to-self

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!