plus character in forms

Posted on 2009-02-17
Last Modified: 2013-12-25
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:


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?
Question by:SandmanNet
    LVL 15

    Expert Comment

    check and convert it to %2B

    whole list of url escape codes
    LVL 2

    Author Comment

    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"?
    LVL 15

    Accepted Solution

    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);

    Open in new window

    LVL 2

    Author Comment

    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.
    LVL 15

    Expert Comment

    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.
    LVL 2

    Author Comment

    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 :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    Title # Comments Views Activity
    Automatic Image Uploading 9 49
    website content maintenance 3 44
    SP to delete duplicates 15 46
    Conditional Link URL - Easy Question 4 31
    SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    This video teaches users how to migrate an existing Wordpress website to a new domain.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now