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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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