This project is archived and is in readonly mode.

#102 ✓invalid
Mateus Pádua

bug with $('form').toQueryString()

Reported by Mateus Pádua | June 9th, 2008 @ 06:38 PM | in 2.0 (closed)

I found a mistake when I trying to use this method below, in fields that have special characters such as accents, for example: "áéãâü" and so on. The solution was as follows:

In this line, the method "toQueryString()" which was implemented to object "Element":

// queryString.push (name + '=' + encodeURIComponent (val));

by this:

queryString.push (name + '=' + escape (val));

I changed the "encodeURIComponent" by function "escape".

I hope I have helped you.

Comments and changes to this ticket

  • digitarald

    digitarald June 9th, 2008 @ 10:47 PM

    escape is deprecated. encodeURIComponent can require UTF-8, what are you using?

  • Mateus Pádua

    Mateus Pádua June 10th, 2008 @ 09:16 PM

    I live in Brazil and here we use iso-8859-1 to be compatible with our language that has very accents, such as "á é ç ã," and others.

    And understand that when using the function encodeURIComponent (), it turns all the special characters in UTF-8 encoding, forcing the use of the function utf8_decode () in PHP to decode the string, in an inclusion in a database for data are not so truncated "ááççãã".

    Ex: mysql_query ( "INSERT INTO rh (name, last_name) VALUES (".

    " '". utf8_decode ($ _POST [ 'name']). " '."

    " '". utf8_decode ($ _POST [ 'last_name']). "')");

    Note the use of the function utf8_decode () to solve the problem.

    Even with the escape() it carries data in characters iso-8859-1, which facilitates the time to record in the database and does not require the function utf8_decode (), thus:

    Ex: mysql_query ( "INSERT INTO rh (name, last_name) VALUES (".

    " '". $ _POST [ 'Name']. " '."

    " '". $ _POST [ 'Last_name']. "')");

    So I gave the suggestion to place the escape() instead of encodeURIComponent (), but as you said this function is deprecated, then what would be the best solution?

    This is a problem that many face in countries where the language requires a lot of emphasis(accents).

    I thank the attention now.

  • Mateus Pádua

    Mateus Pádua June 10th, 2008 @ 09:26 PM

    Here is a link on the subject,

    Thanks (Obrigado)

  • digitarald

    digitarald June 11th, 2008 @ 08:23 AM

    Utf-8 is also compatible with Portuguese, it has all your accents. Ajax requests are encoded utf-8 internally by the Browser. It also supports various languages without escaping or any special code. Utf-8 is therefore the best choice for nearly every language and i18n.

    iso-8859-development has also stopped, utf-8 is future-proof!

    One simple solution would be, that you override encodeURIComponent with escape.

  • Mateus Pádua

    Mateus Pádua June 11th, 2008 @ 09:12 PM

    Thank you for help, I was really wrong, the best solution is to use encodeURIComponent.

    Until I discovered a good way to do this when you have data sent to UTF-8 encoding for PHP. The solution would be before starting to use any of the array as $ _POST in PHP putting this line:

    $ _POST = Array_map (utf8_decode, $ _POST);

    It will enter into all the contents from $ _POST array and decodes them and can use the data so clean after that, this way:

    var_nome $ = $ _POST [ "name"]

    var_email $ = $ _POST [ 'email']

    var_telefone $ = $ _POST [ "tel"]

    Not needing to use use this:

    $ var_nome = utf8_decode ($ _POST [ 'name'])

    $ var_email = utf8_decode ($ _POST [ 'email'])

    $ var_telefone = utf8_decode ($ _POST [ "tel"])


  • Thomas Aylott

    Thomas Aylott June 16th, 2008 @ 04:57 PM

    • State changed from “new” to “invalid”

    So, can we close this ticket now?

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket