![]() |
Euro sign shows as € when form is submitted - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Euro sign shows as € when form is submitted (/showthread.php?tid=52802) |
Euro sign shows as € when form is submitted - El Forum - 06-27-2012 [eluser]cheungj[/eluser] Hi all! I've been using CodeIgniter for the past month but this is my first post. I'm having an issue with the encoding of the € sign. The form is pre-populated with values from the database. In one of the textareas, there are € signs. They show on the form as normal, but after the form is submitted, I retrieve the value, and it appears as either € or it is omitted. I noticed that it shows as € when set like so: Code: <form action="[removed]" method="post" accept-charset="utf-8"> So I changed the accept-charset to ISO-8859-1. With this setting, the € sign was omitted. I have also tried using ISO-8859-15, to no avail. I have tried changing the meta tag's charset, which didn't work either. Does anybody have any ideas? Additional Info To display the form in the view, I am actually using: Code: echo form_open('[removed]', array('accept-charset' => 'ISO-8859-1')); Euro sign shows as € when form is submitted - El Forum - 06-27-2012 [eluser]boltsabre[/eluser] Sounds like an encoding issue, using UTF-8 isn't the problem, it's making sure you use it EVERYWHERE (same can be said about any charset). What is your database collation? What is your meta charset? Are you escaping your data? If so how? Is it ajax? Sending data from Ajax to PHP can also cause issues, you need to uft8_decode($your string) it. Euro sign shows as € when form is submitted - El Forum - 06-27-2012 [eluser]cheungj[/eluser] [quote author="boltsabre" date="1340800289"]Sounds like an encoding issue, using UTF-8 isn't the problem, it's making sure you use it EVERYWHERE (same can be said about any charset). What is your database collation? What is your meta charset? Are you escaping your data? If so how? Is it ajax? Sending data from Ajax to PHP can also cause issues, you need to uft8_decode($your string) it.[/quote] I had an issue with this before, but when I was inserting into the database. Database Collation: latin1_swedish_ci Meta Charset: ISO-8859-1 I'm not escaping the data, nor am I using AJAX to transfer information. I just tried to utf8_decode($var) the string and the same thing happens -- it either shows as a question mark or it is blank. Euro sign shows as € when form is submitted - El Forum - 06-28-2012 [eluser]cheungj[/eluser] Has anybody got any idea about this? Euro sign shows as € when form is submitted - El Forum - 06-28-2012 [eluser]InsiteFX[/eluser] htmlentities Euro sign shows as € when form is submitted - El Forum - 06-29-2012 [eluser]cheungj[/eluser] [quote author="InsiteFX" date="1340914711"]htmlentities [/quote] Thanks for the response. htmlentities didn't work for me though. Ok, I want to better explain this... Currently, my database is storing the € sign as '& euro;' (without the space). I am displaying it in a textarea on a form as the euro sign -- €. I'm then retrieving the textarea in a post in the controller: Code: $description $this->input->post('description'); This is when 'accept-charset' => 'ISO-8859-15' OR when 'accept-charset' => 'ISO-8859-1'. When 'accept-charset' => 'UTF-8', the € sign is displayed as €. It seems as if the form's accept-charset is incorrect. Euro sign shows as € when form is submitted - El Forum - 06-30-2012 [eluser]cheungj[/eluser] I have a workaround for this at the moment. Basically, I'm storing the € sign in the database as its HTML equivalent -- & euro; (without the space). I'm displaying it onto the page (from within the view) using: Code: $this->form_validation->set_value('description', $description) I'm using Code: $this->input->post('description'); Lastly, in my view, I have set the <i>accept-charset</i> like so: Code: echo form_open('controller/function, array('accept-charset' => 'ISO-8859-1')); When I retrieve the POST value, it is a € sign instead of & euro;. So I then convert it back to html using: Code: $description = str_replace('€', '€', $description) Thanks for all the help with this! It was really bugging me. |