#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    1
    Rep Power
    0

    Exclamation Dealing with special characters in forms


    hi,

    I'm having a problem with a form filled textarea and special characters. When the form is submitted to be parsed by a PHP script, all the special character entities are presented to the script as translated text.

    An example:

    The user is presented with a form that has the following predefined textarea:

    <textarea id="b88" name="body[88]" cols="72" rows="12">
    <p>&amp;pound; &lt;= crazy</p>
    </textarea>

    When the form is submitted, the data in the textarea is translated so that the special character codes are replaced with there text equivalent.

    The weird thing is if the user is presented with a blank textarea and they enter "<p>&amp;pound; &lt;= crazy</p>", the browser will retain the special character codes.

    So... the million dollar question: How do you ensure that your special characters are maintained in there encoded format upon submission?

    Thanks,

    Michael

    PS - for what it is worth, my page uses the following character set:
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  2. #2
  3. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    19
    Try escaping them:

    <textarea id="b88" name="body[88]" cols="72" rows="12">
    <p>&amp;amp;pound; &amp;amp;lt;= crazy</p>
    </textarea>

    Alternatively, using scripting:

    <form>
    <textarea id="b88" name="body[88]" cols="72" rows="12"></textarea>
    <input type="submit">
    </form>
    <script type="text/javascript" language="javascript">
    var el = document.forms[0]['body[88]'];
    el.value = '<p>&amp;pound; &amp;lt;= crazy</p>';
    </script>

    btw - had to escape these twice to get this board to print them unrendered!

IMN logo majestic logo threadwatch logo seochat tools logo