Reputation: 6955
I have a page that views photos
, each photo
is in an album
.
At the top of the page I have an albums
select box with the album_id
and album_name
respectively.
<form action="change-album.php" method="get">
<table>
<tr>
<td><label>Select Album</label></td>
<td><select name="album_id"><?=$albums_str?></select></td>
<td><input type="submit" name="change-album" value="Select Album" /></td>
</tr>
</table>
</form>
The default is uncategorised photos
on page load, and then the user can select their album and press submit
, which returns the photos from that album.
Originally this form used POST.
However, if a user selects an album
, AND THEN clicks a photo
. They will see a large version of the photo. But if a user presses BACK on the browser, it says FORM MUST BE RE-SENT
. And this is because the last request on that page posted the album_id
to fetch the photos.
I decided the use GET. Therefore when the user goes BACK
to that page, the album_id
is in the query string! No form re-send! YAAY!
However, Obviously using GET will also send the submit button in the querystring!
So I end up getting:
localhost/admin/view-photos?album_id=1&change-album=Select+Album
Is there anyway I can remove this from the query string?
Or can anybody think of a better way to achieve this?
I want to remove it from the query string because it doesn't really need to be there. its useless
Upvotes: 3
Views: 2103
Reputation: 31730
If you don't need the button's name anywhere in the script then just don't give the submit button a name attribute.
<input type="submit" value="Select Album" />
If you do need it for some part of your script but want to discard it so it doesn't get stored in the database when you're done with it, then just unset it.
unset ($_GET ['change-album']);
Upvotes: 1
Reputation: 250902
When a form is submitted, it is converted into key-value pairs, so if there is no name, or no value the element is not sent:
<form action="change-album.php" method="get">
<table>
<tr>
<td><label>Select Album</label></td>
<td><select name="album_id"><?=$albums_str?></select></td>
<td><input type="submit" value="Select Album" /></td>
</tr>
</table>
</form>
Upvotes: 1
Reputation: 3042
You can remove the submit button from the request array if you remove the name
attribute of the button <input>
.
So in your case, you will have to modify the following:
<input type="submit" name="change-album" value="Select Album" />
To be the one below instead:
<input type="submit" value="Select Album" />
Upvotes: 8
Reputation: 75598
Remove the name attribute:
<input type="submit" value="Select Album" />
Upvotes: 1