akabugeyes Posted July 15, 2006 Share Posted July 15, 2006 Hi, I have created a filter system for a program I am creating that allows the users to select items from a multiple select box and see results with columns that contain one of the selected choices.That much I have working. It is just when I want to use method="get" so it can be linked to, the url looks really bad.With the current system the url comes out like this:[code]index.php?action=filter&platform%5B%5D=DS&platform%5B%5D=GBA&genre%5B%5D=RPG&genre%5B%5D=Adventure&submit=Submit[/code]Where the options for the platform select: 'DS' and 'GBA' have been selected and the options for the genre select: 'RPG' and 'Adventure' have been selected.What I would ideally like to do is get rid of all those %5B%5D characters in the url, I think it may have something to do with the use of making the name of selects an array (<select name="name[]"). I would also like to get rid of the submit=Submit if possible and condense the different selections into a comma separated list.So the url could look something like:index.php?action=filter&platform=DS,GBA&genre=Adventure,RPG Does anyone know what could help me accomplish this? Would this even be possible by using the method="get" or would I perhaps need to use method="post" and maybe redirect using the header() function to the proper place?Any advice would be appreciated. :) Quote Link to comment https://forums.phpfreaks.com/topic/14682-form-link/ Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 Whenever you put symbols in links (suchs as commas) it was automatically encode the URL properly...hence the reason you have all those funky things in there.How are you appending the variables to the link. Can you post some code? Quote Link to comment https://forums.phpfreaks.com/topic/14682-form-link/#findComment-58541 Share on other sites More sharing options...
akabugeyes Posted July 15, 2006 Author Share Posted July 15, 2006 Well in Filter.php I have:[code] foreach($_GET['genre'] as $gen) { $filter['genre'][] = $gen; } $filter['genre'] = implode(',',$filter['genre']); // Same routine for platform! ;) $filter['platform'] = array(); foreach($_GET['platform'] as $plat) { $filter['platform'][] = $plat; } $filter['platform'] = implode(',',$filter['platform']);[/code]And the template code looks like this:[code] <form action="index.php" method="get"> <fieldset class="row2"> <legend>Do we have a platform to filter by?</legend> <input name="action" value="filter" type="hidden" /> <select name="platform[]" multiple="multiple"> <option value="all" selected="selected" style="font-weight: bold;">All</option> <option value="DS">DS</option> <option value="GBA">GBA</option> </select> </fieldset>'; echo ' <fieldset class="row2" style="margin-top: 10px;"> <legend>How about filtering by genre?</legend> <select name="genre[]" multiple="multiple"> <option value="all" selected="selected" style="font-weight: bold;">All</option> <option value="RPG">RPG</option> <option value="Adventure">Adventure</option> </select> </fieldset> <input type="submit" value="Submit" name="submit" /> </form>';[/code]When I echo $filter['genre'] I get: RPG,Adventure and when I echo $filter['platform'] I get: DS,GBA, which they are used with FIND_IN_SET for the where part of my mysql query, but that doesn't really have to do with the link being produced. Quote Link to comment https://forums.phpfreaks.com/topic/14682-form-link/#findComment-58545 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 Even though the URL is ugly, does it actually work? Quote Link to comment https://forums.phpfreaks.com/topic/14682-form-link/#findComment-58547 Share on other sites More sharing options...
akabugeyes Posted July 15, 2006 Author Share Posted July 15, 2006 Yes it does work. Quote Link to comment https://forums.phpfreaks.com/topic/14682-form-link/#findComment-58548 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 Maybe try using different symbols to implode it with? Since the comma is looking funky, try a period or a plus sign. Quote Link to comment https://forums.phpfreaks.com/topic/14682-form-link/#findComment-58549 Share on other sites More sharing options...
akabugeyes Posted July 15, 2006 Author Share Posted July 15, 2006 Actually the implode doesn't really have anything to do with the url being produced.The reason I use implode is so I can use it in the mysql query$filter['where'] = "FIND_IN_SET(`for`, '{$filter['platform']}') AND FIND_IN_SET(`genre`, '{$filter['genre']}')";Basically the url: index.php?action=filter&platform=DS,GBA&genre=Adventure,RPG is something I'd like to do but I have no current code that does anything for it to work.Ignoring the characters being put in the url, the url currently looks like index.php?action=filter&platform=DS&platform=Adventure&genre=RPG&genre=AdventureSo if I can't get it to separate with a comma or plus sign, it would be nice to at least get rid of those extra characters getting produced in the url. Quote Link to comment https://forums.phpfreaks.com/topic/14682-form-link/#findComment-58552 Share on other sites More sharing options...
pixy Posted July 15, 2006 Share Posted July 15, 2006 I dont know WHY it would give you those wierd characters if you took the commas out. & is used to append the variables to the URL, so they shouldn't change...Can you access the page through page.php?action=filter&platform=DS&platform=Adventure&genre=RPG&genre=Adventure Quote Link to comment https://forums.phpfreaks.com/topic/14682-form-link/#findComment-58554 Share on other sites More sharing options...
wildteen88 Posted July 15, 2006 Share Posted July 15, 2006 If you want to make the URL cleaner, why not submit the form to itself. The process the data into the url you want it to be, rather then how the browser formats the url. A bit like this:[code]<?phpif(isset($_POST['submit'])){ foreach($_POST['genre'] as $gen) { $filter['genre'][] = $gen; } $filter['genre'] = implode(',' , $filter['genre']); // Same routine for platform! ;) $filter['platform'] = array(); foreach($_POST['platform'] as $plat) { $filter['platform'][] = $plat; } $filter['platform'] = implode(',' , $filter['platform']); // format our nice url header("Location: index.php?action=filter&genra={$filter['genre']}&platform={$filter['platform']}");}?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <fieldset class="row2"> <legend>Do we have a platform to filter by?</legend> <input name="action" value="filter" type="hidden" /> <select name="platform[]" multiple="multiple"> <option value="all" selected="selected" style="font-weight: bold;">All</option> <option value="DS">DS</option> <option value="GBA">GBA</option> </select> </fieldset> <fieldset class="row2" style="margin-top: 10px;"> <legend>How about filtering by genre?</legend> <select name="genre[]" multiple="multiple"> <option value="all" selected="selected" style="font-weight: bold;">All</option> <option value="RPG">RPG</option> <option value="Adventure">Adventure</option> </select> </fieldset> <input type="submit" value="Submit" name="submit" /></form>[/code]What it'll now do is process the submit data, and format the url so its like this:index.php?action=filter$genra=blah,blah$platform=blah,blahThen on the page you proces the data with you just have to use $_GET['genera'] and $_GET['platform'] whch you can now use in your database. Quote Link to comment https://forums.phpfreaks.com/topic/14682-form-link/#findComment-58556 Share on other sites More sharing options...
akabugeyes Posted July 15, 2006 Author Share Posted July 15, 2006 Thanks for the help wildteen and pixy. :)I have essentially gotten it working.My urls are now starting to look like this:index.php?action=filter&platform=DS,GBA&genre=RPG,Adventurewhich is what I wanted, in part by taking the advice given by wildteen to use post instead of get and then use a header to redirect it.I think the current way I have it coded is using a bit too much repitive coding, but I think I can work on fixing that. :)Thanks for the support! Quote Link to comment https://forums.phpfreaks.com/topic/14682-form-link/#findComment-58635 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.