1

I'm trying to give element of a drupal form using the form_alter hook a title that contains special characters (é,è,à ...)

    $form['title'] = array(
          '#type' => 'textfield',
          '#title' => 'this is my title é à test',
          '#required' => TRUE
          ); 

that gives me a blank output on the form page

using the check_plain() function for the title does not affect the output :s ,still blank I though it's an encoding problem but I checked all my enc settings (database,server,theme template) they are all set to utf-8

please note that when entering a value that contain special characters everything goes normal . i think the problem here is about Drupal core doesn't accept special characters in its #title field ?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
McVeeeee
  • 11
  • 2
  • Have you tried encoding them? i.e. "this is my title é à test" – Ilia Draznin Feb 17 '11 at 22:06
  • does passing it through t() do anything? – bkildow Feb 17 '11 at 22:06
  • @ilia @bkildow : i tried both method but nothing is working , i think there is a problem with the module i'm creating because i tried to test the output of a test page using the menu hook ,if the page contain some special caracters ,there are not showen ! may be the module need to specify it's own encoding ? – McVeeeee Feb 17 '11 at 22:10

2 Answers2

0

Well, first, you should use english in code and then translate it.

Check the encoding of that file...

If you try it outside of drupal, just a plain PHP fail that prints these characters, does it work?

Berdir
  • 6,881
  • 2
  • 26
  • 38
  • the module i'am creating ,must be in french,any way i tried this code : ` header('Content-type: text/plain; charset=UTF-8'); echo "hello éééééééé"; ` and this what i get : hello ������� there are 8 blank caracters instead :s , i guess it is because of a wrong apache server configuration ? – McVeeeee Feb 17 '11 at 22:31
  • Yes, but you should still write it in english in code and then translate it, just like the rest of core. You can provide a .po file with the translations with the module. And no, I don't think that's a problem with Apache, that's a problem with your Editor/File system. What OS are you on? Maybe your editor has an option to save it as UTF-8 when saving. If you have a linux/unix system available, try "file yourfile.php", that should print the encoding then. – Berdir Feb 17 '11 at 22:39
  • i'm on windows xp sp3 ,the ammout of data does'nt allow me to write in english then translate ,any way when i tried this code : header('Content-type: text/plain; charset=ISO-8859-15'); echo "helo éééééééé"; i got the wanted output !any possible way to change Drupal encoding ? – McVeeeee Feb 17 '11 at 22:47
  • No. You are not supposed to change the encoding of Drupal, that is forced you UTF-8. You need to change the encoding of your file. See http://stackoverflow.com/questions/1681568/change-files-encoding-recursively-on-windows for some ways to do that. Or use an editor/IDE that supports selecting the encoding. – Berdir Feb 17 '11 at 23:35
0

I too faced some similar problems with french module. I agree that Berdir's solution is the recommended one but if you really need to put accents in your code you have to encode first your files.

In Notepad++ you can you the Encode menu to achieve this, select "Encode in UTF-8 (without BOM)" and check the bottom right of your file to see its format, it should say "ANSI as UTF-8".

Removing BOM is very important as it can "messed up" Linux servers.

Encode in UTF-8 (without BOM)

tostinni
  • 193
  • 6