Hi,
I have a form to email script here and whenever someone puts "à, é, etc" anything with an accent in the name or last name section it says that it is invalid.
Also I would like to make the telephone number area required... Might you know how?
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info@cjsmo.org";
$email_subject = "Un nouveau formulaire est rempli";
function died($error) {
// your error code can go here
echo "Il semble y avoir une erreur avec le formulaire que vous tentez d'envoyer.";
echo "Voici ces erreurs:<br /><br />";
echo $error."<br /><br />";
echo "Merci de corriger ces erreurs avant de tenter de renvoyer le formulaire.<br /><br />";
die();
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$sexe = $_POST['sexe']; // not required
$telephone = $_POST['telephone']; // not required
$email = $_POST['email']; // required
$experience = $_POST['experience']; // required
$checkbox_html = '';
// lets process them now.
$checkboxes = $_POST['DomaineInteret'];
if(empty($checkboxes)) {
echo("");
$checkbox_html = '';
} else {
$N = count($checkboxes);
echo("");
for($i=0; $i < $N; $i++) {
echo($checkboxes[$i] . " ");
// instead of echoing you could..
$checkbox_html .= $checkboxes[$i]. "\n";
}
}
$checkbox_html2 = '';
// lets process them now.
$checkboxes2 = $_POST['qualifications'];
if(empty($checkboxes2)) {
echo("");
$checkbox_html2 = '';
} else {
$N = count($checkboxes2);
echo("");
for($i=0; $i < $N; $i++) {
echo($checkboxes2[$i] . " ");
// instead of echoing you could..
$checkbox_html2 .= $checkboxes2[$i]. "\n";
}
}
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'Votre adresse courriel est invalide.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'Veuillez remplir toutes les sections qui affichent une *<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'Veuillez remplir toutes les sections qui affichent une *.<br />';
}
if(strlen($experience) < 2) {
$error_message .= 'Vous devez remplir la section "expertise".<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
} $email_message = "Formulaire rempli par $last_name, $first_name\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Prelast_name: ".clean_string($first_name)."\n";
$email_message .= "Nom: ".clean_string($last_name)."\n";
$email_message .= "Sexe: ".clean_string($sexe)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Courriel: ".clean_string($email)."\n";
$email_message .= "
Domaine d'interet:\n". $checkbox_html;
$email_message .= "
Qualifications:\n". $checkbox_html2;
$email_message .= "
Experience et Expertise: ".clean_string($experience)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<script type="text/javascript">
<!--
window.location = "http://www.dev.cjsmo.org/devenirbenevole2.php"
//-->
</script>
<?php } ?>