Jump to content

Archived

This topic is now archived and is closed to further replies.

Jocka

get rid of "GET" in url (query string?)

Recommended Posts

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=Dallas

instead 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

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites

×

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.