Welcome Guest, Not a member yet? Register   Sign In
Submitting textbox results in latin conversion not UTF8?
#1

[eluser]Zero-10[/eluser]
I cannot find a solution to this and I really hope someone can help me out with this. Textbox are submitting in Latin to the database even though it seems to be setup correctly.

In the database, the specific column is utf8_general_ci

In my controller I have added
Code:
$this->load->helper('text');

As per suggested by another thread. This did nothing.

The help document says it's automatic and my view has:
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Looks fine to me.

Everything else gets data passed through without a problem but it's the darn textbox that kills it. I don't know how to force feed the form to convert to UTF-8 but all the other boxes seem to be converting pretty darn well.

Here's the code for the textbox without the CSS elements:
Code:
<textarea id="body_text" name="body_text" maxlength="2500" value="<?= set_value('body_text'); ?>"></textarea>

As for my controller, here is the function that submits the data:
Code:
if ($this->input->post('upload')) {
  $this->load->helper('text');
  $this->createnews->do_upload();
  }

And lastly, the validation for the textbox:
Code:
$this->form_validation->set_rules('body_text', 'Article', 'required|htmlspecialchars|max_length[2500]|xss_clean');

I've tried to get rid of the XSS_CLEAN and got rid of the TEXT helper, but still no dice. Thank you for your time and help me spare this fustration!

EDIT:

What I aim to do in the end is be able to support an alternative language and special characters as well as line breaks and the like. When viewing an article characters like "<" will not be parsed but rather an array of bbcode will be used instead (security reasons). For now I'm just looking for the ability to send that data to the database. Again, it works fine with input=text but not a full <textbox>
#2

[eluser]jakelehner[/eluser]
Are you setting the character set and collation in your CI database config?

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

You could also try setting the 'accept' or 'accept-charset' parameters in your form declaration. I've never had to use these but it might help identify if the issue is in the form processing, CI layer, or database.
#3

[eluser]jakelehner[/eluser]
Also, is the default database collation something other than utf8? I'm not sure how CI handles columns that have differing collations than the table or database. It might be that the database or table collation is taking precedence over the column declaration.
#4

[eluser]Zero-10[/eluser]
The column is properly set and so is the database config file.

Like I said, it works for everything else BUT posting new articles. Even posting comments works fine but articles, even though that it's basically the same code, it doesn't really post properly. It has to be the revised code but it doesn't look any different.
#5

[eluser]Aken[/eluser]
As far as CI is concerned, it has no idea what type of input the text came from. Could be hidden, text, textarea, submit button. It won't target textareas specifically - it has to be something manipulating the data.

- Try removing all form validation rules except for required.
- Do you have any Javascript that changes form values at all?
- What does your do_upload() method do? Does it manipulate anything? Does it use the xss_clean TRUE parameter of $this->input->post() ?
#6

[eluser]Zero-10[/eluser]
I figured it out last night and as it turns out I was using htmlspecialchars during validation. The sad part is that I had skipped this because the two validations that I was comparing were exactly the same length but didn't have all of the same values. So I glanced at it and dismissed that it could be the problem.

Now I'm off to a new journey, converting bbcode into html syntaxes. off I go, and thanks everyone!




Theme © iAndrew 2016 - Forum software by © MyBB