Jump to content

Append Form Submitted GET to the URL?


chaseman

Recommended Posts

I now know how to append GET over normal hyperlinks, but I don't know how to do it with form submissions.

 

Here's the problem:

 

I have a form like this one:

 

<form method="GET" action="">

<?php 
require_once ('sort_category_func.php');
$switch = 1;
sort_category ($switch); 
?>

+ Most Liked <input type='checkbox' value='mostLiked' name='mostLiked' />
<br />
<input type="submit" name="sortSubmit" value='Go' />
<br /><br />
</form>

 

 

And the variables:

 

// DROP DOWN MENU VARIABLES
$select_category = $_REQUEST['sort_category'];
$most_liked = $_GET['mostLiked'];

 

I'm using a while loop to list user submission, you can also sort them by category which works over GET, this works as long as there is no GET data already in the URL, but as soon as there is GET data it won't work anymore.

 

Here's an example:

 

If I have a user profile page opened like this:

 

profile.php?user=konopkov

 

And a category has been chosen to sort the user's submissions the URL will change to:

 

profile.php?sort_category=Logos

 

INSTEAD it should be:

 

profile.php?user=konopkov&sort_category=Logos

 

As I said I know how to achieve this with hyperlinks now, but I have no clue how do it with form submissions.

 

Any suggestions?

 

Thanks.

Link to comment
Share on other sites

You could either add a hidden input field

<form action="action.php" method="get">
<input type="hidden" name="user" value="<?php echo $user; ?>" />
<!-- form stuff -->
</form>

or add it to the action of your form

<form action="action.php?user=<?php echo $user; ?>" method="get">
<!-- form stuff -->
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.