Jump to content


Photo

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


  • Please log in to reply
4 replies to this topic

#1 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 05 October 2006 - 05:16 PM

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

#2 paul2463

paul2463
  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 05 October 2006 - 05:22 PM

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
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
}


dont know if that would work buts its the best I can come up with right now..
you cannot affect the past but you can ruin a perfectly good present by worrying about the future

*********************************************************************
The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource

#3 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 05 October 2006 - 05:29 PM

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

#4 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 05 October 2006 - 06:12 PM

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)
function create_query(){
  var qstring = 'search.php'
  if(document.form.name.value !== NULL){
     qstring = qstring . '?name=' . document.form.name.value
  }

  windows.location = qstring
}
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.

#5 rab

rab
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 17 October 2006 - 11:35 PM

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)

function create_query(){
  var qstring = 'search.php'
  if(document.form.name.value !== NULL){
     qstring = qstring . '?name=' . document.form.name.value
  }

  windows.location = qstring
}
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.


im pretty sure its window.location not windows.location




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users