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(/>/g, ">").replace(/</g, "<").replace(/"/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(/>/g, ">")
.replace(/</g, "<")
.replace(/"/g, '"')
.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(/&/g, "&")
.replace(/à/g, "à")
.replace(/è/g, "è")
.replace(/ì/g, "ì")
.replace(/ò/g, "ò")
.replace(/ù/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, "&")
.replace(/>/g, ">")
.replace(/</g, "<")
.replace(/"/g, """)
.replace(/'/g, "'")
.replace(/à/g, "à")
.replace(/è/g, "è")
.replace(/ì/g, "ì")
.replace(/ò/g, "ò")
.replace(/ù/g, "ù")
;
},
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.