[Configuration] Test longueur d'un champs
Bonjour,
J'ai un formulaire que j'envoi par mail et je voudrais bloqué un champs à 14 caractères.
Voici mon code.
Merci
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| if (isset($_POST['cmdEnvoyer'])) {
require_once('TestFormulaire_fr.php');
// Register the subclasses to use
$v['z'] = new ValidateRequired('Option DEVIS / COMMANDE', $_POST['optChoix']);
$v['er'] = new ValidateRequired('Nom', $_POST['txtNom']);
$v['s'] = new ValidateRequired('Prénom', $_POST['txtPrenom']);
$v['e'] = new ValidateEmail($_POST['txtMail']);
$v['t'] = new ValidateRequired('Adresse', $_POST['txtAdresse']);
$v['u'] = new ValidateRequired('Code Postal', $_POST['txtCP']);
$v['v'] = new ValidateRequired('Ville', $_POST['txtVille']);
$v['w'] = new ValidateRequired('Téléphone', $_POST['txtTelephone']);
$v['x'] = new ValidateSerie($_POST['txtNumSerie']);
$v['y'] = new ValidateRequired('1ère mise en circulation', $_POST['txtMiseEnCircu']);
$errorMsg = '';
// Perform each validation
foreach($v as $validator) {
if (!$validator->isValid()) {
while ($error=$validator->getError()) {
$errorMsg.="<li>".$error."</li>\n";
}
}
}
if ($errorMsg != '') {
print ("<div style='color:red'>Les erreurs suivantes se sont produites:\n<ul>".$errorMsg."</ul></div>");
} else {
if($_POST['cmbClient']=="OUI") $Client ="OUI";
else $Client="NON";
$Num = $_POST['txtNum'];
$Societe = $_POST['txtSociete'];
$Nom = $_POST['txtNom'];
$Prenom = $_POST['txtPrenom'];
$Mail = $_POST['txtMail'];
$Adresse=$_POST['txtAdresse'];
$CP=$_POST['txtCP'];
$Ville=$_POST['txtVille'];
$Telephone=$_POST['txtTelephone'];
if($_POST['cmbNumSerie']=="WDB") $TypeSerie ="WDB";
elseif($_POST['cmbNumSerie']=="WDC") $TypeSerie ="WDC";
elseif($_POST['cmbNumSerie']=="VSA") $TypeSerie ="VSA";
elseif($_POST['cmbNumSerie']=="WME") $TypeSerie ="WME";
elseif($_POST['cmbNumSerie']=="TCC") $TypeSerie ="TCC";
else $TypeSerie ="WDF";
$NumSerie=$_POST['txtNumSerie'];
$MiseEnCircu=$_POST['txtMiseEnCircu'];
$Des1=$_POST['txtDes1'];
if($_POST['cmbRef1']=="Mannes") $TypeRef1 ="Mannespièces";
elseif($_POST['cmbRef1']=="Mercedes") $TypeRef1 ="Mercedes";
else $TypeRef1="---";
$Ref1=$_POST['txtRef1'];
$Qte1=$_POST['txtQte1'];
$Des2=$_POST['txtDes2'];
if($_POST['cmbRef2']=="Mannes") $TypeRef2 ="Mannespièces";
elseif($_POST['cmbRef2']=="Mercedes") $TypeRef2 ="Mercedes";
else $TypeRef2="---";
$Ref2=$_POST['txtRef2'];
$Qte2=$_POST['txtQte2'];
$Des3=$_POST['txtDes3'];
if($_POST['cmbRef3']=="Mannes") $TypeRef3 ="Mannespièces";
elseif($_POST['cmbRef3']=="Mercedes") $TypeRef3 ="Mercedes";
else $TypeRef3="---";
$Ref3=$_POST['txtRef3'];
$Qte3=$_POST['txtQte3'];
$Commentaire=$_POST['txtCommentaire'];
$Destinataire = "nicolas.giltaire@mannes.fr" ;
if($_POST['optChoix']=="Devis") $Sujet ="Mannespieces.fr - Devis";
else $Sujet="Mannespieces.fr - Commande";
$Message = "\n
Client : $Client \n
N° : $Num \n
Société : $Societe \n
Nom : $Nom \n
Prénom : $Prenom \n
Adresse : $Adresse \n
Code Postal : $CP \n
Ville : $Ville \n
Téléphone : $Telephone \n \n
Véhicule concerné : \n
N° de série : $TypeSerie $NumSerie \n
Mis en circualtion : $MiseEnCircu \n \n
Détail de la demande : \n
Désignation 1 : $Des1 \n
Référence 1 : $TypeRef1 $Ref1 \n
Le client en souhaite $Qte1 \n \n
Désignation 2 : $Des2 \n
Référence 2 : $TypeRef2 $Ref2 \n
Le client en souhaite $Qte2 \n \n
Désignation 3 : $Des3 \n
Référence 3 : $TypeRef3 $Ref3 \n
Le client en souhaite $Qte3 \n \n \n
Commentaire du client : $Commentaire ";
$Entetes = "From: $Mail " ;
$EnvoiMail = mail($Destinataire, $Sujet, $Message, $Entetes);
if ($EnvoiMail == true){
echo "<script language=\"JavaScript\" type=\"text/JavaScript\">
document.location = 'MailSucces_fr.php'
</script>";
} else{
echo "<script language=\"JavaScript\" type=\"text/JavaScript\">
document.location = 'MailError_fr.php'
</script>";
}
}
}
?>
class ValidateSerie extends Validator {
/**
* Private
* $email the email address to validate
*/
var $Serie;
//! A constructor.
/**
* Constucts a new ValidateEmail object subclass or Validator
* @param $email the string to validate
*/
function ValidateSerie ($Serie){
$this->Serie=$Serie;
Validator::Validator();
}
//! A manipulator
/**
* Validates an email address
* @return void
*/
function validate() {
$pattern=
"/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
if(!preg_match($pattern,$this->Serie)){
$this->setError('N° de série non valide');
}
if (strlen($this->Serie)><14){
$this->setError('N° de série non valide');
}
}
} |
La rien ne se passe et le mail ne part pas