Handling special chars (apostrophes,backslashes,etc) in html forms across multiple pages

Posted on 2004-11-19
Last Modified: 2010-04-06
In my html forms, I have textfields and textarea's that will contain backslashes and/or apostrophes.  The problem is I have multiple forms across multiple pages.

I post the data from the first page onto the second page, and its put into hidden fields.  Special characters are automatically escaped with a backslash.  The problem is, if the user goes back, the data is posted to the first page and the special characters are escaped again!

So for example, on page 1, if a user enters "I can't type" in the textarea and hits submit:

Page 2 will contain a hidden input field with the value "I can\'t type" and some other input boxes.  If the user hits back, the data is submitted to page 1.

Page 1 will get the posted data as "I can\\\'t type" and then my php script will put that data into the text area.

What's the best way to deal with this problem?  The pages use php, javascript and html forms.

Question by:JonAqua
    LVL 35

    Expert Comment

    > Special characters are automatically escaped with a backslash.


    The browser should handle that on its own...
    LVL 9

    Expert Comment

    I agree with TimYates, it is strange. Could you post PHP code?

    Author Comment

    Nevermind sorry, I found what I needed after posting this but the website wasnt loading for some reason and I got busy with another project.

    >> Special characters are automatically escaped with a backslash.
    >The browser should handle that on its own...

    Yes when I referred to it being done automatic I was referring to the browser.

    For anyone else that has a similiar problem, I just used the php function stripslashes.

    Accepted Solution

    PAQed with points refunded (250)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
    There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now