0

Say I have e.g: (foo.com/index.php?a=1) and a form on it to submit data, but when the submit is hit the url refreshes and it gets rid of the values from the attached.

How do I make the url on my page to stay same as before even when the sumbit button is clicked.

Thanks

Simon
  • 3
  • 3

2 Answers2

2

Like this: action="yourpage.php?var1=value1&var2=value2". You can get these with PHP like so: $var1 = $_GET['var1'].

Example:

<form method="post" action="yourpage.php?var1=value1&var2=value2">
[...]
</form>

You can do this to add existing variables into the url:

<form method="post" action="yourpage.php?var1=<?php echo $_POST['var1'];?>&var2=<?php echo $_POST['var2'];?>">
[...]
</form>
<!-- Output:
<form method="post" action="yourpage.php?var1=value1&var2=value2">
[...]
</form>
-->
0

Change the form action in the HTML to post. i.e.:

<form action="..." method="post">

Assuming its a get at the moment. Then set action to your URL

garryp
  • 5,508
  • 1
  • 29
  • 41