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

    Join Date
    Jan 2003
    Rep Power

    Exclamation Dealing with special characters in forms


    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>

    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?



    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
    Rep Power
    Try escaping them:

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

    Alternatively, using scripting:

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

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

IMN logo majestic logo threadwatch logo seochat tools logo