Welcome Guest, Not a member yet? Register   Sign In
Problems with unicode in forms
#1

[eluser]XploD[/eluser]
Hello. I'm new to CodeIgniter and a PHP newbie. I started following the tutorial in guide and I'm already facing problems with it. I created the form for news in tutorial and unicode characters (like čšćđ) doesn't work. When I echo them in HTML, they work (I'm using
Code:
<meta http-equiv="Content-Type" c charset=UTF-8" />
in my header.php), but when submiting them through form into database, I get ? instead of that characters. I tried utf_unicode_ci collation but it doesn't work neither.

Furthermore, the function for generating slug from title deletes that characters. For example, my title is "Testč" and the generated slug is "test" but I want it to be "testc" so č goes to c, ć to c, đ to d, š to s etc.

Please help.
#2

[eluser]ortwin.van.vessem[/eluser]
Make sure your HTML content has:

Code:
<meta http-equiv="Content-Type" c charset=UTF-8" />

The problem mostly with your database collation, you must make it utf-8 since your

Code:
$db['default']['dbcollat'] = 'utf8_general_ci';

is not the same as your database collation.

Change it to:

Code:
$config['charset'] = "UTF-8";

Config database:

Code:
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_unicode_ci";
#3

[eluser]XploD[/eluser]
I tried unicode and general and none of them works. So, currently I set my database and all tables to utf8_general_ci, I have this in database.php

Code:
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';

In my config.php I have:

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

The view where the form is has:

Code:
<meta http-equiv="Content-Type" c charset=utf-8" />

This is the start of the form:

Code:
<form acti method="post" accept-charset="utf-8" class="stdform" id="registration_form" name="registration_form">

This is my model:

Code:
<?php
class Users extends CI_Model {

public function __construct()
{
  $this->load->database();
}

public function add_user(){
  $data = array(
   'name' => $this->input->post('regname'),
   'surname' => $this->input->post('regsurname'),
   'email' => $this->input->post('regemail'),
   'password' => $this->input->post('regpass')
  );
  
  return $this->db->insert('users', $data);
}
}

This is my controller:

Code:
<?php
class Home extends CI_Controller {

public function index()
{
  $this->load->helper('form');
  $this->load->library('form_validation');
  
  $this->form_validation->set_rules('regname', 'Name', 'trim|required|xss_clean');
  $this->form_validation->set_rules('regsurname', 'Surname', 'trim|required|xss_clean');
  $this->form_validation->set_rules('regemail', 'E-mail', 'trim|required|xss_clean|valid_email');
  $this->form_validation->set_rules('regpass', 'Password', 'trim|required|bcrypt|min_length[6]|max_length[20]');
  $this->form_validation->set_rules('regpassagain', 'Repeat password', 'trim|required|matches[regpass]|bcrypt|min_length[6]|max_length[20]');
  
  if ($this->form_validation->run() == FALSE)
  {
   $this->load->view('welcome');
  }
  else
  {
   $this->load->model('users');
   $this->users->add_user();
   $this->load->view('success');
  }
}
}

And my success view currently displays only text (no HTML at all). Please help, I don't know what to do anymore Sad And I tried all that with utf_unicode_ci as well but it didn't work.
#4

[eluser]InsiteFX[/eluser]
Code:
// HTML 4.01: <meta http-equiv="content-type" content="text/html; charset=UTF-8">

// New in HTML 5: <meta charset="UTF-8">
#5

[eluser]XploD[/eluser]
Tried both of them, none doesn't work. I tried to play with both utf8_unicode_ci and utf8_general_ci and no success. The problem is definitely in the database because I tried to echo data from form in my success view and it works:

https://www.dropbox.com/s/tjzd7i6b92mrtn...161841.png

But then again I looked into database and it's like this:

https://www.dropbox.com/s/noygd74i21bn96...161904.png

This is my database:

https://www.dropbox.com/s/1g32rxbnl451xm...161941.png

My database.php https://www.dropbox.com/s/6jncvjva5db4ot...162026.png

My config:php https://www.dropbox.com/s/za6fwacsz5yosl...162059.png

View which contains form: https://www.dropbox.com/s/orvi4w50au842t...162204.png

My model for adding data to database: https://www.dropbox.com/s/tk4k1qr84101x0...162507.png

I tried EVERYTHING and don't know what to do. This Code Igniter is starting to frustrate me and I'm considering an idea to write my page by myself, without framework. I never had this problem when I was working without framework; unicode characters worked everytime.
#6

[eluser]InsiteFX[/eluser]
Did you create your database with utf8_unicode_ci Collate?

Also in your form validation rules you have bcrypt that is an invalid form validation rule.

I am not going to copy and paste links, if you want to post links use the Post Reply its a full editor.
#7

[eluser]XploD[/eluser]
No, I didn't select anything while I was creating the database. I edited that in phpMyAdmin later. Because, before using CodeIgniter, when I was writing from scratch, I always just created the database, connected to it and unicode characters worked. I will try to create another database from scratch with utf8_unicode_ci.

Links are not my fault. It's a forum protection against spam and bots (I received an error when I tried to insert a link). I'm sorry but there's no other way than copy/paste links. I can create a blank HTML file on my website with links if you want.
#8

[eluser]XploD[/eluser]
I solved the problem. So sorry for bothering you, I was so stupid and I hate this phpMyAdmin. I didn't know that every field in a table has it's own collation. My database and tables were in utf8_unicode_ci but fields in that table were in utf8_swedish_ci.

Sorry once again and thank you a lot!
#9

[eluser]InsiteFX[/eluser]
In the future you can make sure the Collation is correct by doing the below.
Code:
-- ----------------------------------------------
--
-- Table structure for table `ci_sessions`
--

DROP TABLE IF EXISTS `ci_sessions`;

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
  `session_id`    varchar(40)           DEFAULT '0' NOT NULL,
  `ip_address`    varchar(45)           DEFAULT '0' NOT NULL,
  `user_agent`    varchar(120)                      NOT NULL,
  `last_activity` int(10)      unsigned DEFAULT 0   NOT NULL,
  `user_data`     text                              NOT NULL,
  PRIMARY KEY (`session_id`),
  KEY `last_activity_idx` (`last_activity`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

-- ----------------------------------------------
--
-- Dumping data for table `ci_sessions`
--




Theme © iAndrew 2016 - Forum software by © MyBB