Jump to content

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


Jocka

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
Link to comment
https://forums.phpfreaks.com/topic/23091-get-rid-of-get-in-url-query-string/
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..
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.
  • 2 weeks later...
[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

Archived

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

×
×
  • 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.