Cookies and non-ascii characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gabo
Forum Newbie
Posts: 3
Joined: Tue Jun 17, 2008 12:44 pm

Cookies and non-ascii characters

Post by gabo »

Hello!
I'm want create a form for creating invoices. When I open the page there is one row for a one item. Next to the this row I've a "add new row" link which add one more row. When "add new row" link was clicked the page reloade and the filled data was lost, so I save every input element to cookies with onChange.
I know just few very simple things from javascript.
My problem is a non-ascii character...
The cookie is saved OK, but loaded back without some character like "?,š,?,? ....". The page is in UTF-8.

Code: Select all

 
<?php 
 $oneHour = (mktime(date('h')+1)); 
 $oneHour = date('r',$oneHour); // The life time of the cookie
 function restoreValue($thisID, $defValue) { 
   if (isset ($_COOKIE[$thisID])) { 
    echo $_COOKIE[$thisID]; 
   } else { 
    echo $defValue; 
   } 
 } 
?>
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<script type="text/javascript"> 
 function setcookie(Cname, Cvalue) { 
 var expire = "<?php echo $oneHour; ?>"; 
 document.cookie = Cname+"="+Cvalue+"; expires="+expire+"; path=/"; 
 } 
</script> 
</head>
 
<form> 
 <input name="Description" id="Description" type="text" value="<?php restoreValue('Description','The description field');?>" onchange="setcookie(this.id, this.value);"/> 
</form>
Thank you very much for any help.

G.
Post Reply