$_POST empty on utf-8 characters

前端 未结 4 663
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 15:27

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

相关标签:
4条回答
  • 2020-12-03 16:11

    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.

    0 讨论(0)
  • 2020-12-03 16:15

    Make sure the form tag has accept-charset:

    <form method="post" action="" accept-charset="utf-8">
    

    Then in the controller use utf8_decode() when fetching the posted values:

    $value = utf8_decode($this->input->post('field_name'));
    
    0 讨论(0)
  • 2020-12-03 16:25

    This isnt an answer, but you might want to take a look and see how everything is coming in.

    
    foreach($_POST as $key => $val)
    {
         $post_data[$key] => $val;
    }
    print_r($post_data);
    

    then try with CI's post

    
    foreach($_POST as $key => $val)
    {
         $post_data[$key] => $this->input->post($key);
    }
    
    print_r($post_data);
    
    0 讨论(0)
  • 2020-12-03 16:29

    If you don't want to use a previous PHP version in your MAMP instalation you can use:

    $_REQUEST

    To get the data instead of $_POST

    $_REQUEST is an associative array that by default contains the contents of $_GET, $_POST and $_COOKIE.

    More info: http://php.net/manual/en/reserved.variables.request.php

    And that returns all the data that for some reason $_POSTis breaking !

    0 讨论(0)
提交回复
热议问题