[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

plus character in forms

So, I have this gaming site, and people have a search form where they can search for game titles. Yesterday, I found a bug with this and I'm unsure where the bug is - with the browser or if there is something I can do.

There is a game called "N+", which is its complete title. But, when searching for that using a form that has GET as the method, the resulting URL will be:

/games/list.php?search=N+

That may look right, but "+" in url's are treated as spaces (even though an url encoded space is %20) and as such, that url would send the value "N " as the search string, which of course wouldn't match the games.

Is there anyting one can do to remedy this?
0
SandmanNet
Asked:
SandmanNet
  • 3
  • 3
1 Solution
 
quincydudeCommented:
check and convert it to %2B

whole list of url escape codes
http://www.aptana.com/docs/index.php/URL_Escape_Codes
0
 
SandmanNetAuthor Commented:
How do I check and convert it? I mean - it's sent as a part of the form submittng. So in the recieving end (the form action target) I get "N ". At what point should I "check and convert it"?
0
 
quincydudeCommented:
before submit the form.

you can use the event onsubmit() to make a javascript to replace all presence of the + sign to %2B. Using something like below
<script type="text/javascript">
var replaceStr = "%2B";
var myOldString = "Hello+world+friend";
var myNewString = myOldString.replace(/\+/g, replaceStr );
 
document.write("Old string =  " + myOldString); 
document.write("<br />New string = " + myNewString);
 
</script>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
SandmanNetAuthor Commented:
Uhm, so you're saying that the only way to remedy this "bug" is to put a javascript handler on every form (since I'd like to remedy this for all forms, not just the game search form)?

That seems like an awfully awkward way of handling things, especially if the user doesn't have JS turned on. Hmmm.
0
 
quincydudeCommented:
I dun think it's a bug but just some kind of communication mismatch between client and server. The concern is on why the client browser do not encode it and the server side do not decode it properly.

I am just pointing out one possible way to handle this.
And more, nowadays js is already a essential part of web pages, if js is not enabled many page functions simply don't work. Then do you mean you will avoid all tasks made by javascript? If not then your reply of "especially if the user doesn't have JS turned on." doesnt make sense at all.
0
 
SandmanNetAuthor Commented:
No, I didn't mean to complain about your solution, I'm sure it works as described. I just expressed a frustration over having to resort to JS to solve a problem you describe as something between the client and server... :/ I'll award you points soon, unless a betetr solution shows up soon enough :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now