par
konjiki » 13 nov. 2005, 23:13
salut, j'ai un probleme avec une expression reguliere et je vois pas trop d'ou ca vient! le but est de verifier un code postal et ...ca marche pô.j'ai l'erreure suivante :
Warning: Invalid argument supplied for foreach() in c:\www\ciridd\formulaire 4\traitement.php on line 39
j'ai mis un commentaire à la ligne 39,voila mon code:
<?php
//champs a tester dans un tableau
$chps_test=array("nom" => "nom",
"prenom" => "prenom",
"cp" => "code_postal",
"mail" => "e-mail");
//echo "test depart ok <br> ";
//controle de tous les champs vides
foreach($_POST as $cle => $valeur)
{if ($valeur=="")
{ //if{ $cle != "cp" ) { tous obligatoire sauf cp
{$champvide[$cle] = "blanc";}
}
elseif ($cle == "prenom" or $cle== "nom" )
{if (!ereg("^[A-Za-z' -]{1,50}$" ,$_POST[$cle]))
{$mauvaisformat[$cle]="mauvais";}
}
elseif ($cle == "mail" )
{if (!ereg("^.+@.+\..+$", $valeur))
{$mauvaisformat[$cle]="mauvais";}
}
elseif ($cle == "cp" )
{if (!ereg("^[9-0]{5}?$", $valeur))
{$mauvaisformat[$cle]="mauvais";}
}
}
//echo "control de champ ok <br>";
//si un champ vide afficher message
if (@sizeof($champvide) > 0 or @sizeof($mauvaisformat) > 0) // en cas de champ vide
{
echo "<b>un champs obligatoire n'a pas ete renseigne.
vous devez le saisir :</b><br>";
// affichage des informations requises
foreach($champvide as $cle => $valeur)
{echo " {$chps_test[$cle]}<br>";}
}
if (@sizeof($mauvaisformat) > 0)
{echo "<b>Un ou plusieurs champs contiennent des informations qui semblent
incorrectes. Corriger le format de : </br><br>";
foreach($mauvaisformat as $cle => $valeur) //ligne 39
{echo " {$chps_test[$cle]}<br>";}
}
//mise en forme des données
$nom=trim(strip_tags($_POST['nom']));
$prenom=trim(strip_tags($_POST['prenom']));
$mail=trim(strip_tags($_POST['mail']));
$cp=trim(strip_tags($_POST['cp']));
//affichage formulaire
echo "<p><hr>
<form action='traitement.php' method='POST'>
<center>
<table width='95%' border='0' cellspacing='0' cellpadding='2'>
<tr>
<td align='right'><B>{$chps_test['nom']}:</br></td>
<td><input type'text' name='nom' size='35' value='$nom'></td>
</tr>
<tr>
<td align='right'><B>{$chps_test['prenom']}:</br></td>
<td><input type'text' name='prenom' size='35' value='$prenom'></td>
</tr>
<tr>
<td align='right'><B>{$chps_test['cp']}:</br></td>
<td><input type'text' name='cp' size='35' value='$cp'></td>
</tr>
<tr>
<td align='right'><B>{$chps_test['mail']}:</br></td>
<td><input type'text' name='mail' size='35' value='$mail'></td>
</tr>
</table>
<p><input type='submit' value='validez'>
</form>
</center>";
exit();
echo "ca marche";
?>
merci de votre aide
salut, j'ai un probleme avec une expression reguliere et je vois pas trop d'ou ca vient! le but est de verifier un code postal et ...ca marche pô.j'ai l'erreure suivante :
Warning: Invalid argument supplied for foreach() in c:\www\ciridd\formulaire 4\traitement.php on line 39
j'ai mis un commentaire à la ligne 39,voila mon code:
[php]<?php
//champs a tester dans un tableau
$chps_test=array("nom" => "nom",
"prenom" => "prenom",
"cp" => "code_postal",
"mail" => "e-mail");
//echo "test depart ok <br> ";
//controle de tous les champs vides
foreach($_POST as $cle => $valeur)
{if ($valeur=="")
{ //if{ $cle != "cp" ) { tous obligatoire sauf cp
{$champvide[$cle] = "blanc";}
}
elseif ($cle == "prenom" or $cle== "nom" )
{if (!ereg("^[A-Za-z' -]{1,50}$" ,$_POST[$cle]))
{$mauvaisformat[$cle]="mauvais";}
}
elseif ($cle == "mail" )
{if (!ereg("^.+@.+\..+$", $valeur))
{$mauvaisformat[$cle]="mauvais";}
}
elseif ($cle == "cp" )
{if (!ereg("^[9-0]{5}?$", $valeur))
{$mauvaisformat[$cle]="mauvais";}
}
}
//echo "control de champ ok <br>";
//si un champ vide afficher message
if (@sizeof($champvide) > 0 or @sizeof($mauvaisformat) > 0) // en cas de champ vide
{
echo "<b>un champs obligatoire n'a pas ete renseigne.
vous devez le saisir :</b><br>";
// affichage des informations requises
foreach($champvide as $cle => $valeur)
{echo " {$chps_test[$cle]}<br>";}
}
if (@sizeof($mauvaisformat) > 0)
{echo "<b>Un ou plusieurs champs contiennent des informations qui semblent
incorrectes. Corriger le format de : </br><br>";
foreach($mauvaisformat as $cle => $valeur) //ligne 39
{echo " {$chps_test[$cle]}<br>";}
}
//mise en forme des données
$nom=trim(strip_tags($_POST['nom']));
$prenom=trim(strip_tags($_POST['prenom']));
$mail=trim(strip_tags($_POST['mail']));
$cp=trim(strip_tags($_POST['cp']));
//affichage formulaire
echo "<p><hr>
<form action='traitement.php' method='POST'>
<center>
<table width='95%' border='0' cellspacing='0' cellpadding='2'>
<tr>
<td align='right'><B>{$chps_test['nom']}:</br></td>
<td><input type'text' name='nom' size='35' value='$nom'></td>
</tr>
<tr>
<td align='right'><B>{$chps_test['prenom']}:</br></td>
<td><input type'text' name='prenom' size='35' value='$prenom'></td>
</tr>
<tr>
<td align='right'><B>{$chps_test['cp']}:</br></td>
<td><input type'text' name='cp' size='35' value='$cp'></td>
</tr>
<tr>
<td align='right'><B>{$chps_test['mail']}:</br></td>
<td><input type'text' name='mail' size='35' value='$mail'></td>
</tr>
</table>
<p><input type='submit' value='validez'>
</form>
</center>";
exit();
echo "ca marche";
?>[/php]
merci de votre aide