Bonjour Cyrano est merci pour ta réponse. Je tenais à m'excuser pour ma réponse tardive mais je n'ai pas eu le temps matériel de m'occuper de mon formulaire avant...
Sinon, j'ai mis en application les informations données et j'ai réglé quelques problèmes.
Malheureusement il m'en reste quatre :
-> Réaffichage des informations de la checkbox "information" :
La checkbox étant cochée par défaut, si on la décoche et l'on valide le formulaire en ayant un champ invalide, elle revient cochée !!!
-> Réaffichage des champs "nomassoc" ou "profession" :
Après une validation avec un champ incorrecte les champs "nomassoc" ou "profession" ne réapparaissent pas alors que le bouton "association" est validé. Il faut recliquer sur "oui" ou "non" pour faire réapparaitre le champ !!!
-> Avoir le champ "nomassoc" vide si le bouton radio "association" est sur NON et inversement avoir le dans le champ "profession" vide si le bouton radio "association" est sur OUI :
Comment effacer le contenu du champ "nomassoc" lorsqu'il a été renseigné (bt radio "association" sur "Oui") car il reste plein si l'on met ensuite le le bouton radio "association" sur "Non". C'est identique par inversement avec le champ "profession" !?!?
-> Fonctionnement de 'Recommencer' après la validation du formulaire avec un champ obligatoire vide :
Impossible de vider l'intégralité des champs après la validation du formulaire qui a un champ invalide. Seuls les champs se trouvant à partir de celui invalide sont vidés !!!
Une fois c'est quatre problèmes réglés je pourrais enfin mettre en place le formulaire...
MERCI POUR VOTRE AIDE.
Code mis à jour :
<script type="text/javascript">
function radioclick (b)
{
document.getElementById('div1').style.display = (b!=1? 'none':'block');
document.getElementById('div2').style.display = (b!=2? 'none':'block');
}
</script>
<?php
// On récupère les champs du formulaire s'ils ont été envoyés, et on arrange leur mise en forme
$civilite = (isset($_POST['civilite'])) ? $_POST['civilite'] : "";
$nom = (isset($_POST["nom"])) ? trim(stripslashes($_POST["nom"])) : "";
$prenom = (isset($_POST["prenom"])) ? trim(stripslashes($_POST["prenom"])) : "";
$adresse = (isset($_POST["adresse"])) ? trim(stripslashes($_POST["adresse"])) : "";
$Adresse2 = (isset($_POST["adresse2"])) ? trim(stripslashes($_POST["adresse2"])) : "";
$codepostal = (isset($_POST["codepostal"])) ? trim(stripslashes($_POST["codepostal"])) : "";
$ville = (isset($_POST["ville"])) ? trim(stripslashes($_POST["ville"])) : "";
$pays = (isset($_POST["pays"])) ? trim(stripslashes($_POST["pays"])) : "FRANCE";
$association = (isset($_POST['association'])) ? $_POST['association'] : "";
$nomassoc = (isset($_POST["nomassoc"])) ? trim(stripslashes($_POST["nomassoc"])) : "";
$profession = (isset($_POST["profession"])) ? trim(stripslashes($_POST["profession"])) : "";
$Email = (isset($_POST["Email"])) ? trim(stripslashes($_POST["Email"])) : "";
$message = (isset($_POST["message"])) ? trim(stripslashes($_POST["message"])) : "";
$modalite = (isset($_POST['modalite'])) ? $_POST['modalite'] : "";
$information = (isset($_POST['information'])) ? $_POST['information'] : "";
$prenom = str_replace(" ", "-", $prenom);
function myUcfirst($capture) { return $capture[1].ucfirst($capture[2]); }
$prenom = preg_replace_callback("#(^|['~-])(\w+)#", "myUcfirst", $prenom);
function majusculesnom($nom) {$nom = strtoupper($nom); $nom = strtr($nom, "äâàáåãéèëêòóôõöøìíîïùúûüýñçþÿæœðø","AAAAAAEEEEOOOOOØIIIIUUUUYÑÇÞYÆŒÐØ"); return $nom; }
$nom = majusculesnom($nom);
function majusculesville($ville) {$ville = strtoupper($ville); $ville = strtr($ville, "äâàáåãéèëêòóôõöøìíîïùúûüýñçþÿæœðø","AAAAAAEEEEOOOOOØIIIIUUUUYÑÇÞYÆŒÐØ"); return $ville; }
$ville = majusculesville($ville);
function majusculespays($pays) {$pays = strtoupper($pays); $pays = strtr($pays, "äâàáåãéèëêòóôõöøìíîïùúûüýñçþÿæœðø","AAAAAAEEEEOOOOOØIIIIUUUUYÑÇÞYÆŒÐØ"); return $pays; }
$pays = majusculesville($pays);
/* On vérifie si le formulaire a été envoyé */
if (isset($_POST["Valider"]))
{
$etat = "erreur";
/* Après la mise en forme, on vérifie la validité des champs */
if (empty($civilite)) {
$erreur="Vous n'avez pas indiqué votre civilité.";
}
elseif (empty($nom)) {
$erreur="Vous n'avez pas indiqué votre nom.";
}
elseif (!ereg("^[^-][[:alpha:]'~-]+[^-]$", $nom)) {
$erreur="Votre nom est mal orthographié."; //
}
elseif (empty($prenom)) {
$erreur="Vous n'avez pas indiqué votre prénom.";
}
elseif (!ereg("^[^-][[:alpha:]'~-]+[^-]$", $prenom)) {
$erreur="Votre prénom est mal orthographié.";
}
elseif (($codepostal != "") && (!eregi("^[0-9]{5}$",$codepostal))) {
$erreur="Le code postal saisi n'est pas valide.";
}
elseif (empty($ville)) {
$erreur="Vous n'avez pas indiqué votre ville.";
}
elseif (!ereg("^[^-][[:alpha:]'~-]+[^-]$", $ville)) {
$erreur="Le nom de votre ville est incorrect.";
}
elseif (empty($Email)) {
$erreur="Vous n'avez pas indiqué votre adresse e-mail.";
}
elseif (!eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,4}$",$Email)) {
$erreur="Votre adresse e-mail n'est pas valide.";
}
elseif (empty($association)) {
$erreur="Vous n'avez pas indiqué si vous étes membre d'une association.";
}
elseif (empty($soutien)) {
$erreur="Vous n'avez coché la case 'modalité'.";
}
else {
$etat="ok";
}
}
else {
$etat="attente";
}
if ($etat!="ok")
{
?>
<!-- Formulaire HTML qu'on affiche dans l'état attente ou erreur -->
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>#formulaire" method="post" name="form1">
<table><tr><td width="530">
<div class="bodyletter">
<?PHP
if ($etat=="erreur")
{
echo "<span style=color:red;>". $erreur ."</span><br />\n";
}
?>
</div>
<div class="bodyletter"><font size="-1">(<font color="#FF0000">*</font>) <em>Champs obligatoires.</em></font><br>
</div>
<table>
<tr valign="baseline">
<td width="90" align="right">Civilité <font color="#FF0000" size="-1">*</font></td>
<td width="170"><input type="radio" name="civilite" value="M."<?php echo($civilite == "M.") ? ' checked="checked"' : null; ?> />M.
<input type="radio" name="civilite" value="Mme"<?php echo($civilite == "Mme") ? ' checked="checked"' : null; ?> />Mme
<input type="radio" name="civilite" value="Mlle"<?php echo($civilite == "Mlle") ? ' checked="checked"' : null; ?> />Mlle</td>
</tr>
</table>
<table>
<tr valign="baseline">
<td width="90" align="right" nowrap>Nom <font color="#FF0000" size="-1">*</font></td>
<td width="121"><input type="text" size="20" name="nom" value="<?php echo htmlspecialchars($nom, ENT_QUOTES); // le nom de l'expéditeur a été saisi --> le réafficher ?>"></td>
<td width="67" align="center" valign="middle"><div align="right">Prénom
<font color="#FF0000" size="-1">*</font> </div></td>
<td width="121" align="right" ><input type="text" size="20" name="prenom" value="<?php echo htmlspecialchars($prenom, ENT_QUOTES); ?>"></td>
</tr>
</table>
<table>
<tr valign="baseline">
<td width="90" align="right" nowrap>Adresse</td>
<td width="320" align="right"><input type="text" size="57" name="adresse" value="<?php echo htmlspecialchars($adresse, ENT_QUOTES); ?>"></td>
</tr>
</table>
<table CELLSPACING="0">
<tr valign="baseline">
<td width="94"><img src="phpPetitionTemplate/mm_spacer.gif" alt="" width="1" height="1" border="0"></td>
<td width="320"><input type="text" size="57" name="adresse2" value="<?php echo htmlspecialchars($adresse2, ENT_QUOTES); ?>" ></td>
</tr>
</table>
<table>
<tr valign="baseline">
<td width="90" align="right" nowrap>Code Postal</td>
<td width="30" align="left"><input name="codepostal" size="5" maxlength="5" type="text" value="<?php echo htmlspecialchars($codepostal, ENT_QUOTES); ?>" ></td>
<td width="49" align="right" nowrap>Ville <font color="#FF0000" size="-1">*</font></td>
<td width="231"align="right" ><input type="text" size="38" name="ville" value="<?php echo htmlspecialchars($ville, ENT_QUOTES); ?>"></td>
</tr>
</table>
<table>
<tr valign="baseline">
<td width="90" nowrap align="right">Pays</td>
<td width="60" align="left"><input type="text" size="10" name="pays" value="<?php echo htmlspecialchars($pays, ENT_QUOTES); ?>" ></td>
</tr>
</table>
<table>
<tr valign="baseline">
<td width="90" nowrap align="right">E-mail<font color="#FF0000" size="-1">
*</font></td>
<td width="160" align="left"><input type="text" size="28" name="Email" value="<?php echo htmlspecialchars($Email, ENT_QUOTES); ?>"></td>
</tr>
</table>
<table>
<tr valign="baseline">
<td width="226" align="left"><div align="left"> Etes-vous membre d'une association ?<font color="#FF0000" size="-1"> *</font></div></td>
<td width="93">
<input type="radio" name="association" value="Oui" onclick="radioclick(1)" <?php echo($association == "Oui") ? ' checked="checked"' : null; ?> />Oui
<input type="radio" name="association" value="Non" onclick="radioclick(2)" <?php echo($association == "Non") ? ' checked="checked"' : null; ?> />Non
</td>
</tr>
</table>
<div id="div1" style="display: none">
<table>
<tr valign="baseline">
<td width="90" nowrap align="right"><div align="left"> Laquelle ?</div></td>
<td width="160" align="left"><input type="text" size="28" name="nomassoc" value="" onfocus="value=''"></td>
</tr>
</table></div>
<div id="div2" style="display: none">
<table>
<tr valign="baseline">
<td width="90" nowrap align="right"><div align="left"> Profession :</div></td>
<td width="160" align="left"><input type="text" size="28" name="profession" value="" onfocus="value=''"></td>
</tr>
</table></div>
<table>
<tr valign="baseline">
<td width="90" align="left" valign="top">
<p> Message :<br>
<font size="-5"> (facultatif)</font></p>
</td>
<td width="287" valign="top">
<textarea name="message" cols="43"rows="3" ><?php echo htmlspecialchars($message, ENT_QUOTES); ?></textarea></td>
</tr>
</table>
<table>
<tr valign="baseline">
<td width="20" align="left"><div align="left">
<input type="checkbox" name="modalite" value="Oui" <?php echo($modalite == "Oui") ? ' checked="checked"' : null; ?> />
</div></td>
<td width="435" valign="middle"> <strong>J'ai pris connaissance des modalités de l'opération. <font color="#FF0000" size="-1">*</font></strong></td>
</tr>
</table>
<table width="533">
<tr valign="baseline">
<td width="20" align="left"><div align="left">
<input name="information" type="checkbox" value="Oui" <?php echo($information == "Oui") ? ' checked="checked"' : checked; ?> />
</div></td>
<td width="501" valign="middle"> Je souhaite être informé(e) du résultat de l'opération.
</td>
</tr>
</table>
<table>
<tr>
<td width="90" align="right"><img src="phpPetitionTemplate/mm_spacer.gif" alt="" width="1" height="1" border="0"></td>
<td width="56" align="right"> <input type="submit" name="Valider" value="Valider" /> </td>
<td width="8"><img src="phpPetitionTemplate/mm_spacer.gif" alt="" width="1" height="1" border="0"></td>
<td width="100" align="left"> <input type="reset" value="Recommencer" />
</td>
</tr>
</table>
<input type="hidden" name="IP" value="<?php Echo $_SERVER['REMOTE_ADDR'] ?>" size="32">
<input type="hidden" name="Date" value="<?php Echo date('Y-m-d H:i:s') ?>" size="32">
<input type="hidden" name="MM_insert" value="form1">
</form>
<?php
}
?>