How to preserve GET parameters when posting form t

2019-06-15 07:26发布

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条回答
Juvenile、少年°
2楼-- · 2019-06-15 08:13

You need to use hidden input instead:

<input type="hidden" name="first" value="<?php echo htmlspecialchars($first, ENT_QUOTES); ?>" />
查看更多
登录 后发表回答