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

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

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

I find that I cannot return the value "測試", I get nothing.

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

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

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

Code From 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>

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);    
} 

View:

      <?php echo $field_name?>
+5
source share
3 answers

I finally solved this, you need to use the javascript function encodeURI to encode the data before sending the message.

0
source

, charset .

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

:

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

.

+2

set the encoding in the configuration file as shown below -

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

Then use the following heading at the top of the page where you need to show / print / enter unicode text -

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

You can also set this title to your index page.

0
source

All Articles