开发者

Why can't I read input values with Chinese characters in Codeigniter?

I pass a value like '測試' to my form, and I get back the value by doing this:

$this->input->post('field_name');

I find that I can't get back the '測試' value, I get nothing.

My version is 2.0.2, and the $config['charset'] = 'UTF-8';

If I echo('測試'), there is no problem.

With Latin characters it works, and prints perfectly. How can I solve it?

Code From the form:

The form

<form target="sc_light_box" action='http://localhost:8888/my_project/index.php/data/add_data.php' method="post">
<textarea id="field_name" name="field_name"/>
<input type="submit" id="submit_button">
</form>

The controller:

public function add_data()
{
       $this->_load_add_data_page();  开发者_开发技巧  
}  


private function _load_add_data_page()
{   
    $this->load->library('form_validation');  
    $this->load->library('table');
    $this->load->helper('form'); 

    $data['field_name']              =$this->input->post('field_name');


    $this->load->view('add_data_page_view', $data);    
} 

The view:

      <?php echo $field_name?>


I have resolved the issue by updating the config file charset value to simple letters.

Before it was

$config['charset'] = 'UTF-8';

and I changed it to :

$config['charset'] = 'utf-8';

Now it works well.


I finally solved it, you need to use the javascript encodeURI function to encodeURI the data, before u post.


set charset in config file as below-

$config['charset'] = 'utf-8';

Then use following header at top of the page in which pageyou need to show/print/input your unicode text-

header('Content-Type: text/html; charset=utf-8');

You can set this header in general into your index page as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜