Note that there are some explanatory texts on larger screens.

plurals
  1. POUTF8 troubles in a php contact form
    text
    copied!<p>Here is my contact function :</p> <pre><code>public static function contact_anon() { $form = new Form('contact_anon'); $form-&gt;field('email', 'text', array ( 'max_length' =&gt; 45, 'valid_email' =&gt; true )); $form-&gt;field('message', 'textarea', array ( 'max_length' =&gt; 400, 'min_length' =&gt; 25 )); if($data = $form-&gt;validate()) { $envoi = array ( 'message' =&gt; $data['message'], 'email' =&gt; $data['email'] ); mail('mymail@gmail.com', lang('contact_anon'), lang('contact_anon_text', $envoi), 'From: noreply@'.$_SERVER['HTTP_HOST']); } return $form; } </code></pre> <p>Then I have this other php file with the content text that will be sent + the message from the form :</p> <pre><code>&lt;?php fw::$lang = array_merge(fw::$lang, array ( 'contact_anon_text' =&gt; "You have been contacted : Message : {message} Mail : {email}" )); </code></pre> <p>The form is working well, but the <code>{message}</code> doesn't display correctly, for example :</p> <pre><code>j\'écris avec des accents pour voir si ça marche. </code></pre> <p>The website has a UTF8 charset, but I don't know about php, I tried the following : </p> <pre><code>'message' =&gt; htmlentities((utf8_decode($data['message']), ENT_QUOTES), </code></pre> <p>But it returns : </p> <pre><code>syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '(' </code></pre> <p>I know there is hundreds of posts about UTF8, I checked them, read the php mnual and sql manual, but couldn't understand so much as I am a beginner and not english speaker.</p> <p>I also have the same problem when sending a text field to the database, eventhough the database is using utf8_general_ci. So I guess it's definitely a problem with my php code. I am using a MVC scripts with controllers. To solve partially the SQL problem, I use :</p> <pre><code>return mysql_real_escape_string($string); .... db::escape($username) </code></pre> <p>So the output is correct, but I had prefer to configure php to use UT8 and allows special characters like french accents.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload