zero-perfoliate
zero-perfoliate

Author Topic: Posting a form with a text box containing a Spanish Accent  (Read 630 times)

Offline McKaulick

  • PHP Workers
  • **
  • Posts: 7
  • Karma: +0/-0
  • McKaulick - http://twitter.com/mckaulick
Posting a form with a text box containing a Spanish Accent
« on: January 25, 2009, 06:34:11 AM »
Hello people,

I have a form where I post a Spanish Word with a Spanish accent on the word. Let's say, the word is Agrícóla.

I submit the form and then I build a mysql query with the content of the text box. Something like this:

select * from farm where FARM_ESTITLE like '%Agrícóla%'

If I print the query in my code, I actually have this:
select * from farm where FARM_ESTITLE like '%Agrícóla%'

This query does not return anything. So I copied this query and tested it insqlyog and it returned rows. But now what is happening is really strange, I copied the query from sqlyog and paste it in my code and refresh the page so it uses this static query instead. Well it actually returned the rows.

Also, the printed query on my page was this:
select * from farm where FARM_ESTITLE like '%Agr�c�la%'

So what I am assuming here is that the accent submitted by the browser is somewhere not recognized when sent to the server. So what I did then is creating a function to change the letter with the accent to the non-accent equivalent and did some testing to see what is happening.

This is what I am doing.

$replace = array(
      'a' => array('à','â','ä'),
      'e' => array('è','ê','ë','é'),
      'i' => array('ì','î','ï','í'),
      'o' => array('ò','ô','ö','ó'),
      'u' => array('ù','û','ü')
);

// loop through all replacements and apply them
foreach ($replace as $by=>$what) {
    $str = str_replace($what,$by,htmlspecialchars($_POST["search"]));
}

// done!
echo $str;
 
<form name="frm" action="testesp.php" method="post">
            <input type="text" value="Agrícóla" name="search">
             <input type="submit" value="ok">
 </form>

You can see test the script here: http://gatewaytosouthamerica.com/mckaulick/testesp.php

Even this does not work. Somewhere, the accent is being ignore by the server. Someone has any thought?

Thanks,
mckaulick

Offline jenovachild

  • New PHP Members
  • Posts: 4
  • Karma: +0/-0
Re: Posting a form with a text box containing a Spanish Accent
« Reply #1 on: February 12, 2009, 09:04:45 PM »
Hey,

I've run into this problem myself it is quite annoying. There are multiple things you may need to do.

1. Make sure your html document is displayed using the UTF-8 charset, by placing the following line within the <head> of your document:

Code: [Select]
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

If you are using anything like phpMyAdmin with your MySQL, make sure you have the option flagged to handle multiple charsets with import and query's, by default this is NOT enabled.

I've also found that, between MAC and WINDOWS, especially when dealing with files with foreign accents, MAC seems to fail almost 100% of the time even when the corrent charsets are being used. If you still can't resolve the issue, come back for more help.
« Last Edit: February 12, 2009, 09:07:45 PM by jenovachild »

Offline McKaulick

  • PHP Workers
  • **
  • Posts: 7
  • Karma: +0/-0
  • McKaulick - http://twitter.com/mckaulick
Re: Posting a form with a text box containing a Spanish Accent
« Reply #2 on: February 17, 2009, 10:23:26 AM »
Hello jenovachild,

Thanks for you answer, did not find on phpmyadmin where to flag the tables to handle multiple charsets. Can you give me more details about where can I find this?

Let me know,
Thanks,
Patrice

Offline PhPHelper

  • http://Digiscapers.com
  • Full Member
  • PHP Problem Solvers
  • ****
  • Posts: 179
  • Karma: +50/-0
    • Bad Apple Mail
Re: Posting a form with a text box containing a Spanish Accent
« Reply #3 on: February 17, 2009, 11:05:41 AM »
on the import menu on phpmyadmin you have the option to select a character set from a drop down menu see the attached image.

Offline jenovachild

  • New PHP Members
  • Posts: 4
  • Karma: +0/-0
Re: Posting a form with a text box containing a Spanish Accent
« Reply #4 on: February 17, 2009, 06:37:41 PM »
Hey,

Apart from that option, there is also the option to convert charset types which you can opt to install in the setup script of your server, or add it manually to the config.inc.php file.

See attached image  for the option. It's under Features > Charsets in the scripts/setup.php directory of your phpMyAdmin.

Otherwise, it's probably easier to just add the following code to your config.inc.php:

Code: [Select]
$cfg['AllowAnywhereRecoding'] = true;
$cfg['DefaultCharset'] = 'utf-8';
$cfg['RecodingEngine'] = 'auto';
$cfg['IconvExtraParams'] = '//TRANSLIT';