[RESOLVED] Local html form (without php) encoding problem
Hi Guys !
AutoCAD has the ability to create a board within the application.
The board that I created is hosted locally (z:\plans\board\ ...) and not on the web. I can do the form but it gets harder at sending the form, special characters appear in place of accents.
Im using Firefox 4.0 on Windows XP Pro and Office 2007...
Re: Local html form (without php) encoding problem
That (what appears in the browser) means that your page isn't really saved as UTF-8. You could change it, but I've tried it for myself and that still doesn't fix what appears in Outlook (other email clients are working just fine though... surprise surprise). I haven't found anything that actually works for Outlook yet...
Re: Local html form (without php) encoding problem
Also when I try your code with IE9, the email body is empty (the form field data is not there). IE9 being new, I'm not familiar with all of its inevitable failings yet - can anyone replicate and confirm this one?
Re: Local html form (without php) encoding problem
since no one else has asked about it... I will... I don't think it's your HTML form... you can make all the changes you want to it... unless Outlook supports unicode it isn't going to make a hill of beans what you do with the HTML form...
The attached screenshot shows what I got on the back end after running the SAME code that was in post #1... all I did was to re-route the To address...
Re: Local html form (without php) encoding problem
Yeah, it seems like Outlook hates Unicode and favors ISO, whereas all other email clients are the opposite.
With the form, I changed the meta charset back to ISO and found one working result, but only in IE9 (I don't have any other IE versions to test with, and it doesn't work in Firefox). I've taken and cobbled some script from this page, and came up with this mess:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="content-type">
<title>Test</title>
</head>
<body>
<form id="myForm" enctype="text/plain" method="post" action="mailto:email@internet.com" name="MyForm">
<input name="txtName" value="Prénom Nom"><br>
<br>
<input type="submit" value="Envoyer la demande...">
</form>
<script>
window.onload = function(){
document.getElementById('myForm').onsubmit = function(){
var mailBody = '';
var inputs = this.getElementsByTagName('input');
for(var j=0;j<inputs.length;j++){
mailBody += inputs[j].name + '=' + changeIt(inputs[j].value) + ',';
}
this.action += '?body='+mailBody;
};
};
var hexVals = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F");
var unsafeString = "\"<>%\\^[]`\+\$\,";
function isUnsafe(compareChar){
if (unsafeString.indexOf(compareChar) == -1 && compareChar.charCodeAt(0) > 32
&& compareChar.charCodeAt(0) < 123){
return false;
}else{
return true;
}
}
function decToHex(num, radix){
var hexString = "";
while (num >= radix){
temp = num % radix;
num = Math.floor(num / radix);
hexString += hexVals[temp];
}
hexString += hexVals[num];
return reversal(hexString);
}
function reversal(s){
var len = s.length;
var trans = "";
for (k=0; k<len; k++){
trans = trans + s.substring(len-k-1, len-k);
}
s = trans;
return s;
}
function convert(val){
return "%" + decToHex(val.charCodeAt(0), 16);
}
function changeIt(val){
var len = val.length;
var newStr = "";
var original = val;
for (i=0;i<len;i++){
if (val.substring(i,i+1).charCodeAt(0) < 255){
if (isUnsafe(val.substring(i,i+1)) == false){
newStr += val.substring(i,i+1);
}else{
newStr += convert(val.substring(i,i+1));
}
}else{
alert ("Found a non-ISO-8859-1 character at position: " + (i+1) + ",\nPlease eliminate before continuing.");
newStr = original; i=len;
}
}
return newStr;
}
</script>
</body>
</html>
As said, I've only seen this work with IE9. Firefox won't seem to accept a ?body argument in the mailto, when the mailto is used as a form action. Whereas IE9 seems to ignore all form fields when the form action is a mailto, but it will still accept ?body. Ugh.
Well, maybe there's something useful in there... or not.
Last edited by SambaNeko; May 27th, 2011 at 01:40 PM.
Re: Local html form (without php) encoding problem
Originally Posted by techgnome
since no one else has asked about it... I will... I don't think it's your HTML form... you can make all the changes you want to it... unless Outlook supports unicode it isn't going to make a hill of beans what you do with the HTML form...
The attached screenshot shows what I got on the back end after running the SAME code that was in post #1... all I did was to re-route the To address...
-tg
Im not sure If I understand when you talk about "re-route the To address" ???
As per your printscreen (...from Windows Internet Explorer), is this works also in Firefox ?
Thanks !
Originally Posted by SambaNeko
Yeah, it seems like Outlook hates Unicode and favors ISO, whereas all other email clients are the opposite.
With the form, I changed the meta charset back to ISO and found one working result, but only in IE9 (I don't have any other IE versions to test with, and it doesn't work in Firefox). I've taken and cobbled some script from this page, and came up with this mess:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="content-type">
<title>Test</title>
</head>
<body>
<form id="myForm" enctype="text/plain" method="post" action="mailto:email@internet.com" name="MyForm">
<input name="txtName" value="Prénom Nom"><br>
<br>
<input type="submit" value="Envoyer la demande...">
</form>
<script>
window.onload = function(){
document.getElementById('myForm').onsubmit = function(){
var mailBody = '';
var inputs = this.getElementsByTagName('input');
for(var j=0;j<inputs.length;j++){
mailBody += inputs[j].name + '=' + changeIt(inputs[j].value) + ',';
}
this.action += '?body='+mailBody;
};
};
var hexVals = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F");
var unsafeString = "\"<>%\\^[]`\+\$\,";
function isUnsafe(compareChar){
if (unsafeString.indexOf(compareChar) == -1 && compareChar.charCodeAt(0) > 32
&& compareChar.charCodeAt(0) < 123){
return false;
}else{
return true;
}
}
function decToHex(num, radix){
var hexString = "";
while (num >= radix){
temp = num % radix;
num = Math.floor(num / radix);
hexString += hexVals[temp];
}
hexString += hexVals[num];
return reversal(hexString);
}
function reversal(s){
var len = s.length;
var trans = "";
for (k=0; k<len; k++){
trans = trans + s.substring(len-k-1, len-k);
}
s = trans;
return s;
}
function convert(val){
return "%" + decToHex(val.charCodeAt(0), 16);
}
function changeIt(val){
var len = val.length;
var newStr = "";
var original = val;
for (i=0;i<len;i++){
if (val.substring(i,i+1).charCodeAt(0) < 255){
if (isUnsafe(val.substring(i,i+1)) == false){
newStr += val.substring(i,i+1);
}else{
newStr += convert(val.substring(i,i+1));
}
}else{
alert ("Found a non-ISO-8859-1 character at position: " + (i+1) + ",\nPlease eliminate before continuing.");
newStr = original; i=len;
}
}
return newStr;
}
</script>
</body>
</html>
As said, I've only seen this work with IE9. Firefox won't seem to accept a ?body argument in the mailto, when the mailto is used as a form action. Whereas IE9 seems to ignore all form fields when the form action is a mailto, but it will still accept ?body. Ugh.
Well, maybe there's something useful in there... or not.
Thanks for your help, I appreciate very much, but I prefer to use Firefox...
DubweiserTM
If your question has been answered, you can mark a thread as resolved...
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu. https://get.cryptobrowser.site/30/4111672
Re: Local html form (without php) encoding problem
No, what Nightwalker83 posted is not relevant (and no, Firefox does not need an inline onsubmit attribute for the function to work).
As techgnome said, this probably doesn't have much to do with the HTML, but with Outlook's ability to support unicode (what techgnome presumably meant by "re-route the To address" was that he sent the email to himself, and opened it with a mail client that properly supports unicode). You can do some Googling to investigate if your Outlook is properly configured for unicode.
Re: Local html form (without php) encoding problem
Hi, me again !
I try all the code below on a Windows 7 computer, and that's okay, on my computer (Windows XP) it's still the same, but most of the users that will use this page are on Windows 7...