Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve GET parameters when posting form to self?

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

like image 525
MultiDev Avatar asked May 09 '12 21:05

MultiDev


1 Answers

You need to use hidden input instead:

<input type="hidden" name="first" value="<?php echo htmlspecialchars($first, ENT_QUOTES); ?>" />
like image 194
zerkms Avatar answered Oct 12 '22 09:10

zerkms