I'm working on a multilingual site with CodeIgniter. There is a form that posts data to controller, but $_POST
is empty when I start to use Turkish characters like öçüÜĞ
etc.
I set the charset to:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Form:
<form action="translations/save" method="post" accept-charset="utf-8">
<textarea rows="6" cols="60" id="editor_tr" name="editor_tr">Türkçe</textarea>
</form>
$_POST
and $this->input->post('editor_tr')
returns empty, but I can see the raw post with file_get_contents("php://input")
.
This one works OK in a normal PHP test, but doesn't work with CodeIgniter. Perhaps my .htaccess file is causing the issue, but dunno.
Any help is much appreciated.
UPDATE: Here is the output for var_dump as requested.
var_dump($_POST)
- Without Turkish chars
array(3) { ["id"]=> string(12) "news8titleID" ["editor_tr"]=> string(13) "turkish value" ["editor_en"]=> string(13) "english value" }
var_dump($_POST)
- With Turkish chars (The input was: Türkçe karakter
, but it doesn't show up in the $_POST)
array(3) { ["id"]=> string(12) "news8titleID" ["editor_tr"]=> string(0) "" ["editor_en"]=> string(13) "english value" }
UPDATE 2:
When debugging, I have found out that system.core.Input
class cleans the input data on _clean_input_data
function.
// Clean UTF-8 if supported
if (UTF8_ENABLED === TRUE)
{
$str = $this->uni->clean_string($str);
}
So, before the $_POST
has reached to my controller, the editor_tr
value is already cleaned by system.core.Utf8
class in this function:
function clean_string($str)
{
if ($this->_is_ascii($str) === FALSE)
{
$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
}
return $str;
}
Since the comments are piling up and will probably get overlooked, I am going to post some more suggestions.
Readers please keep in mind this is dealing with $_POST data values and not display of data on a web page.
This user seems to have a similar problem:
Codeigniter seems to break $_POST of '£' character (Pound)
There is a report here on Bitbucket of similar:
https://bitbucket.org/ellislab/codeigniter-reactor/issue/214/problem-when-inserting-special-characters:
Removed link: EllisLabs has closed this repo to the public
Maybe adding this to your index.php will help (probably not):
ini_set('default_charset', 'UTF-8');
Double check and make sure you aren't running any validation or prepping rules on the field. Things like url_title()
will strip those characters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With