After reading a number of similar questions (UTF-8 all the way through, php form submit utf8? enter link description here, UTF-8 not working in HTML forms enter link description here) and trying all their recommendations, but the user form in my application still can't handle special characters (é, è, etc). A few additional notes:
I can save special characters on the db (Postgres), adding new users or editing existing entries, with no problem. And if I retrieve those entries on the webapp it successfully displays special characters (say, adminPage/usersTable or adminPage/userInfoEdit#).
However, if I try saving that entry it will write gibberish into the db.
PHP Header
<?php header("Content-Type: text/html;charset=UTF-8");
PHP Post
if (empty($_POST) === false && empty($errors) === true) {
$registerData = array(
'email' => $_POST['email'],
'first_name' => $_POST['firt_name'],
'last_name' => $_POST['last_name'],
);
registerUser($registerData);
PHP Function
function registerUser($registerData) {
array_walk($registerData, 'arraySanitize');
pg_query("INSERT INTO utilisateur ($fields, date_inscription, statut) VALUES ($data, '$date','$statut')");
function arraySanitize(&$item) {
$item = htmlentities(strip_tags(pg_escape_string($item)));
}
HTML form
<form method="post" action="" accept-charset="UTF-8">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label>First name *</label>
<input type="text" class="form-control" name="firt_name" value="">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Last name *</label>
<input type="text" class="form-control" name="firt_name" value="">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>email *</label>
<input type="text" class="form-control" name="email" value="">
</div>
</div>
</div>
</form>
Any comments, suggestions, tips, resources will be highly appreciated. If you have any questions, I'm happy to clarify. Thanks a lot!