1. #1
    Ext User rajga's Avatar
    Join Date
    May 2009
    Location
    Milano
    Posts
    1
    Vote Rating
    1
    rajga is on a distinguished road

      1  

    Thumbs up Special chars problem resolved into Combobox, TextField, Loading Form and other Apps

    Special chars problem resolved into Combobox, TextField, Loading Form and other Apps


    Hi all,
    sorry for my bad english... but i hope that be useful with this thread.

    Some time ago, i had a problem with the view of the specials special characters into combobox and on loading a form, reading data in UTF-8 from a store.

    I think that this problem is frequent, because many of us using the standard "utf-8".

    I have upgrade the htmlDecode/htmlEncode function of EXTJS, i have made many tests but there were many problems with the visualization.

    Now i resolved this problem following without this simple procedure and there isn't any problem!


    IN the head of index i have set this standard characters:
    HTML Code:
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    Include this page that contain the function of htmlEncode/htmlDecode:
    HTML Code:
    <script type="text/javascript" src="ext/src/util/Format.js"></script>
    Upgrade the htmlDecode function of EXTJS with this function:
    Code:
    htmlDecode : function(value){
         return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/"/g, '"').replace(/'/g, "'");
    };
    Now, at this function (the new htmlDecode) we can add other type of special characters that we wont convert; for example:
    Code:
            htmlDecode : function(value){
                return !value ? value :
                                    String(value)
                                        .replace(/&gt;/g, ">")
                                        .replace(/&lt;/g, "<")
                                        .replace(/&quot;/g, '"')
                                        .replace(/"/g, '"')
                                        .replace(/'/g, "'")
                                        .replace(/&amp;/g, "&")
                                        .replace(/&agrave;/g, "à")
                                        .replace(/&egrave;/g, "è")
                                        .replace(/&igrave;/g, "ì")
                                        .replace(/&ograve;/g, "ò")
                                        .replace(/&ugrave;/g, "ù")
                                        ;
            },
    Important is of don't forget that for each characters update into the htmlDecode you must update the characters into htmlEncode too.
    for example:
    Code:
            htmlEncode : function(value){
                return !value ? value : String(value)
                                            .replace(/&/g, "&amp;")
                                            .replace(/>/g, "&gt;")
                                            .replace(/</g, "&lt;")
                                            .replace(/"/g, "&quot;")
                                            .replace(/'/g, "'")
                                            .replace(/à/g, "&agrave;")
                                            .replace(/è/g, "&egrave;")
                                            .replace(/ì/g, "&igrave;")
                                            .replace(/ò/g, "&ograve;")
                                            .replace(/ù/g, "&ugrave;")
                                            ;
            },
    On the EXTJS store, set the convert function "htmlDecode" on the interested's field
    (method of reading is JsonReader)
    for example:
    Code:
    var load_conv = new Ext.data.JsonReader({
        root: 'conv',
        autoLoad: true,
        fields:
            [
            {name: 'id_agency', mapping: 'id', type: 'int'},
            {name: 'title', convert: function(v){return Ext.util.Format.htmlDecode(v);}},
            {name: 'email_inc', mapping: 'incaricato_email'},
            {name: 'category', mapping: 'category', convert: function(v){return Ext.util.Format.htmlDecode(v);}},
            ]
    });
    This store, now, can be used for load a form, for a cascade list into a combobox ecc... ecc... ecc...



    When we go to save data with PHP and MySql, this is the codification (htmlentities) that we are going to use:
    PHP Code:
            $sql="
                INSERT INTO "
    .database::tb_utenti."
                    (
                        id_cap,
                        nome,
                        cognome,
                        data_nascita
                    )
                VALUES
                    (
                        "
    .(int)$id_cap.",
                        '"
    .htmlentities($_POST['nome'], ENT_QUOTES"ISO-8859-1")."',
                        '"
    .htmlentities(ucwords(strtolower($_POST['cognome'])), ENT_QUOTES"ISO-8859-1")."',
                        '"
    .$_POST['data_nascita'."'
                    )
            "
    ;
            
    $query=mysql_query($sql); 
    Soon i post an example of this pill.


    I hope it was useful to someone!

    Roberto.
    Attached Images

  2. #2
    Sencha User
    Join Date
    Jun 2008
    Posts
    8
    Vote Rating
    0
    herybarkan is on a distinguished road

      0  

    Default


    Thanks for sharing

  3. #3
    Sencha User
    Join Date
    Mar 2009
    Posts
    2
    Vote Rating
    0
    ljegou is on a distinguished road

      0  

    Default


    Thanks a lot !

  4. #4
    Sencha User
    Join Date
    Apr 2009
    Posts
    1
    Vote Rating
    0
    shivangi.chandra is on a distinguished road

      0  

    Default


    Hi all,

    I had similar problem with special characters in Textfield and applying the above suggested methods (i.e. including meta tag for character encoding and by using the overridden htmlDecode function) the problem got resolved for most of the characters except ‘£’ and ‘¬’.

    These characters are now being saved in database as ‘£’ and ‘¬’ and on UI it rendered as ‘?’. I am using an ajax request to get data and JSON store to load the records in grid and textfield.

    Can anyone please suggest how can this be corrected?

    Thanks.

  5. #5
    Sencha User Ghostly's Avatar
    Join Date
    Apr 2012
    Location
    Whitefish, MT USA
    Posts
    31
    Vote Rating
    2
    Ghostly is on a distinguished road

      0  

    Default


    To just get rid of them...

    <?PHP
    $result=preg_replace("/[^\x9\xA\xD\x20-\x7F]/", "", $result);
    $result=ereg_replace("[[:cntrl:]]", "", $result);
    $result=str_replace("&amp;", '&', $result); // tricky this one
    $result=str_replace("&nbsp;", '', $result);
    ?>

  6. #6
    Sencha User Ghostly's Avatar
    Join Date
    Apr 2012
    Location
    Whitefish, MT USA
    Posts
    31
    Vote Rating
    2
    Ghostly is on a distinguished road

      0  

    Default


    Just get rid of them:

    <?PHP
    $result=preg_replace("/[^\x9\xA\xD\x20-\x7F]/", "", $result);
    $result=ereg_replace("[[:cntrl:]]", "", $result);
    $result=str_replace("&amp;", '&', $result); // tricky this one
    $result=str_replace("&nbsp;", '', $result);
    ?>
    Donnie Martin - noob cake
    Ext JS 4.1 & Architect 2.0 - Ajax/LAMP
    "My email address is older than you, not kidding"

Similar Threads

  1. UTF-8, mySQL and special chars (e.g. german chars)
    By Snoop74 in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 21 May 2010, 9:56 AM
  2. htmleditor special chars
    By mic2100 in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 6 Jul 2008, 3:32 AM
  3. Textfield: issues with special chars
    By Rocketman in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 3 Mar 2008, 11:59 AM
  4. [2.0f] Special chars in a fileUpload form
    By krycek in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 10 Dec 2007, 1:11 PM
  5. comboboxes and special chars
    By tobiu in forum Ext 1.x: Help & Discussion
    Replies: 6
    Last Post: 16 Aug 2007, 3:32 AM

Thread Participants: 4

Tags for this Thread