chaseman Posted February 27, 2011 Share Posted February 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/229043-append-form-submitted-get-to-the-url/ Share on other sites More sharing options...
flolam Posted February 27, 2011 Share Posted February 27, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/229043-append-form-submitted-get-to-the-url/#findComment-1180421 Share on other sites More sharing options...
chaseman Posted February 27, 2011 Author Share Posted February 27, 2011 action variant didn't work for me, but the hidden field variant worked great. In the last and in this thread you rescued my day! I've been working on this since so many hours. Quote Link to comment https://forums.phpfreaks.com/topic/229043-append-form-submitted-get-to-the-url/#findComment-1180438 Share on other sites More sharing options...
PFMaBiSmAd Posted February 27, 2011 Share Posted February 27, 2011 If the form method='get', only the form data is included on the end of the URL. In this case, the only way you can get it to work is by using hidden fields. Quote Link to comment https://forums.phpfreaks.com/topic/229043-append-form-submitted-get-to-the-url/#findComment-1180439 Share on other sites More sharing options...
flolam Posted February 27, 2011 Share Posted February 27, 2011 Good to know, never tried it =) I'm glad I could help! Quote Link to comment https://forums.phpfreaks.com/topic/229043-append-form-submitted-get-to-the-url/#findComment-1180440 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.