Jocka Posted October 5, 2006 Share Posted October 5, 2006 I read up on this a little but couldn't figure out quite how to get it done.What I have is a PHP file with numerous fields for searching. When I submit, the search goes and the url reads out something like: search.php?name=&city=[b]Dallas[/b]&state=&country=What I want this to do is get rid of any empty fields. so it'd end up more like:search.php?city=Dallasinstead of ALL of that showing up. Anyone know how I can get rid of empty GET (query_string)'s?I'm steadily searching google. But that doesn't mean I'll find the answer :P Quote Link to comment Share on other sites More sharing options...
paul2463 Posted October 5, 2006 Share Posted October 5, 2006 could you not write a function to be done onSubmit that takes in all the fields and then only outputs the fields with data in like[code]function removeEmptyFields($_GET['fname'],$_GET['lname'],$_GET['dateOfBirth']) {$answer = "";if ($_GET['fname'] != "") {$answer = $_GET['name']}if ($_GET['lname'] != "") {$answer = $_GET['name']}if ($_GET['name'] != "") {$answer = $_GET['dateOf Birth']}return $answer}[/code]dont know if that would work buts its the best I can come up with right now.. Quote Link to comment Share on other sites More sharing options...
Jocka Posted October 5, 2006 Author Share Posted October 5, 2006 I could probably use javascript to do something like that. now that you mentioned it, i'm looking into it (easier to find on google).any more suggestions are still welcomed Quote Link to comment Share on other sites More sharing options...
Jocka Posted October 5, 2006 Author Share Posted October 5, 2006 Alright. I tried some javascript and can't get it to work although now I'm thinking THAT is the easier way to do it.its something like this (just running one query through)[code]function create_query(){ var qstring = 'search.php' if(document.form.name.value !== NULL){ qstring = qstring . '?name=' . document.form.name.value } windows.location = qstring}[/code]It almost works. I can't get it to redirect or something. It runs through but it wont' redirect correctly.::EDIT:: if a mod wants to move this to the JAVASCRIPT section, be my guest. Quote Link to comment Share on other sites More sharing options...
rab Posted October 17, 2006 Share Posted October 17, 2006 [quote author=Jocka link=topic=110600.msg447381#msg447381 date=1160071923]Alright. I tried some javascript and can't get it to work although now I'm thinking THAT is the easier way to do it.its something like this (just running one query through)[code]function create_query(){ var qstring = 'search.php' if(document.form.name.value !== NULL){ qstring = qstring . '?name=' . document.form.name.value } windows.location = qstring}[/code]It almost works. I can't get it to redirect or something. It runs through but it wont' redirect correctly.::EDIT:: if a mod wants to move this to the JAVASCRIPT section, be my guest.[/quote]im pretty sure its window.location not windows.location Quote Link to comment 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.