well something like that - but I really wouldn’t want to change the way it works as it’s done and dusted now and it works quite well for me because I have only 2 languages to worry about, (fully aware that if I had more this solutions wouldn’t really work).
Basically, here is my file structure:
en
cookies.js
index.php
images
...
it
cookies.js
index.php
PHPMailer-master
...
styles.css
formhandler.php
tablet.css
mobile.css
.htaccess
form_en.js
script.js
etc
The htaccess file has this in it:
#language redirects
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} ^it [NC]
RewriteRule ^$ /it/ [L,R=301]
RewriteRule ^$ /en/ [L,R=301]
and here is the content of the two index.php files:
[php]
<?php
echo ‘
’;
if ($thisLanguage==‘it’) echo ‘- IT
- EN
’;
if ($thisLanguage==‘en’) echo ‘- IT
- EN
’;
echo ‘
’;
?>
[/php]
and
[php]
<?php
echo '
';
if ($thisLanguage=='it') echo '- IT
- EN
';
if ($thisLanguage=='en') echo '- IT
- EN
';
echo '
';
?>
[/php]
So basically when the language link is clicked the appropriate page is loaded.
Now, on to the code you kindly provided me with. I integrated it, but I have some issues.
I've changed the validation slightly
[php]$title = (isset($_POST['title']) && ($_POST['title'] != '0')) ? $_POST['title'] : null;
$firstName = (isset($_POST['firstName']) && !(empty($_POST["firstName"]))) ? $_POST['firstName'] : null;
$lastName = (isset($_POST['lastName']) && !(empty($_POST["lastName"]))) ? $_POST['lastName'] : null;
$emailAddress = (isset($_POST['emailAddress']) && !(empty($_POST["emailAddress"]))) ? $_POST['emailAddress'] : null;
$website = isset($_POST['website']) ? $_POST['website'] : '';
$message = (isset($_POST['message']) && !(empty($_POST["message"]))) ? $_POST['message'] : null;
if ($title === null) {
$errors[] = ‘You must select a title’;
}
if ($firstName === null) {
$errors[] = ‘You must enter a first name’;
}
if ($lastName === null) {
$errors[] = ‘You must enter a last name’;
}
if ($emailAddress === null || filter_var($emailAddress, FILTER_VALIDATE_EMAIL) === false) {
$errors[] = ‘You must enter a valid email address’;
}
if ($website !== ‘’) {
if(strpos($website, ‘://’) === false) {
$website = ‘http://’ . $website;
}
if (filter_var($website, FILTER_VALIDATE_URL, array('flags' => null)) === false) {
$errors[] = 'You must enter a valid website address';
}
}
if ($message === null) {
$errors[] = ‘You must enter a message’;
}[/php]
I will have to change the default error messages as well (the one generated by the required attribute becasue not all browsers support it and because it is causing me issues on the mobile version of the site), but let’s leave this for later.
The issue is with the form submission. Now, let me say first that I couldn’t set up that password for my account, it just says that that service isn’t available to my account (I’ve tried with 2 different gmail accounts so definitely not a problem with the account itself). When I attempt to submit the form, I get a few errors on the form itself:
[code]Warning: Cannot modify header information - headers already sent by (output started at /home/antoniob/public_html/agency_test/test/formhandler.php:1) in /home/antoniob/public_html/agency_test/test/formhandler.php on line 3
Fatal error: Cannot redeclare PHPMailerAutoload() (previously declared in /home/antoniob/public_html/agency_test/test/PHPMailer-master/PHPMailerAutoload.php:24) in /home/antoniob/public_html/agency_test/test/PHPMailer-master/PHPMailerAutoload.php on line 31
[/code]
Now, I believe the second one is because I have inserted a required statement, as you said, at the top of the php file
[php]<?php
require ‘PHPMailer-master/PHPMailerAutoload.php’;
header(‘Content-Type: application/json’);[/php]
But I’ve notice that you have one already:
[php] if (empty($errors)) {
require DIR . ‘/PHPMailer-master/PHPMailerAutoload.php’;[/php]
(I changed the path because that’s where the autoload file sits in)
So I removed mine from the top and left yours in. And what happens is pretty odd. If I fill the form in, it takes about 1-2- minutes to submit it, it just hangs, I can see in the console panel in firebug that the formhandler.php just hangs for a few minutes and then eventually it submits the form and I get a 200 OK message (still in the console): but the form never makes it to my email address, presumably because of the password problem?
For simplicity, here is the full php file http://pastebin.com/GNUc8zau, but if you want to see the thing in action might be best if you try on the live site
EDIT: ah, in fact the form doesn’t get submitted, after two minutes at the bottom of the form you get this:
Request Timeout
This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase ‘Connection Timeout’.
Even though the console says 200 OK