Forum Moderators: coopster

Message Too Old, No Replies

Using two or more language in one php contact form

Using two or more language in one php contact form

         

CreativeFusion

2:12 pm on Jun 17, 2012 (gmt 0)

10+ Year Member



Hi,

Suppose my website address is example.com which is in English.
Now I have a Spanish version at example.com/es/ directory, but my php contact form is only located at example.com/request/index.php.

I want to use the same php contact form for both sites (English and Spanish). So, when anyone from the English site visits my contact page, they will see all the form contents (name, e-mail, address, message etc.) in English and will receive the automatic reply in English. And when anyone from the Spanish site visits the contact form, they will see everything in Spanish and also receive the automatic reply in Spanish.

For this I do not want to use two separate contact form. I want to use the same contact form. So, how can I do it inside the php form (without calling any function from database)? I just want to use PHP (any variables or functions it's ok, but without using any database). I think I have clarified everything clearly. But if you have any confusion about the final goal, please let me know.

rocknbil

4:11 pm on Jun 18, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard CreativeFusion, if it's like most contact forms I see it may be a bit difficult with a bunch of if/else blocks. If you do it as a series of "objects" (or at least, object-like as variables instead of hard-coded phrases,) it shouldn't be all that hard.

Say you have a configuration file. This configuration file will contain all the phrases and words used in the program. I'd store them in some way that associates with language.

Your config file could start off as line items

thank_you|en:Thank You|sp:Gracias

which you'd convert to arrays

$thank_you = Array (
'en' => 'Thank You',
'sp' => 'Gracias'
);

Then when you build your messages, use the values.

$lang=$_POST['lang']; // or $_SESSION, cookie . . .

echo $thank_you[$lang] . '!';