Paul87
Invité n'ayant pas de compte PHPfrance
26 mai 2013, 12:14
voiçi le code complet de ma page FormA.php. (il s'agit d'une page qui permet de proposer ou rechercher des articles médicaux soit grand public soit pro)
en fait, je souhaite que tous les champs obligatoires soient remplis. et que lorsque 'submit' si champs obligatoires maquants message information, mais sans vider complètement les champs déja complétés.
Ou dois-je mettre le code php pour connexion / ajout dans ma BDD si tous les champs ok?
Si tous les champs ok :message du genre "votre demande est enregistrée, elle sera en ligne après validation" puis retour sur index.php
Mille excuses, mon code n'est surement pas très clean, je bidouille et teste ++
De plus, la partie <SCRIPT language="JavaScript"> sert a faire fonctionner le Select Département en fonction du Select Région (Il n'est pas complété en entier à ce stade)
Merci pour ton aide et tes conseils
<?php
if($_POST['send']){
// Var definition
$tit = $_POST["TitrA"] ;//champ obligatoire
$detail = $_POST["Detail"] ; //champ obligatoire
$dep = $_POST["dep"] ;//champ obligatoire
$reg = $_POST["reg"] ;//champ obligatoire
$cat = $_POST["cat"] ;//champ obligatoire
$type = $_POST["type"] ;//champ obligatoire
$pseudo = $_POST["pseudo"] ;//champ obligatoire
$mail = $_POST["mail"] ;//champ obligatoire
$tel = $_POST["tel"] ; //..............................champ pas obligatoire
$cp = $_POST["cp"] ; //.............................champ pas obligatoire
$status = $_POST["status"] ;
// Traitement
$Valid = true;
if(empty($reg)){
$Valid = false;
unset($reg);
echo 'Choix région obligatoire.';
}
if(empty($dep)){
$Valid = false;
unset($dep);
echo 'Choix département obligatoire.';
}
if(empty($tit)){
$Valid = false;
unset($tit);
echo 'Choix du titre obligatoire';
}
if($Valid){
header('Location:confirmation.php');
}
}
//end $_POST;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<HTML>
<TITLE>Formulaire de Dépôt</TITLE>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
<form method="post">
<SCRIPT language="JavaScript">
<!--
function Choix(form) {
i = form.reg.selectedIndex;
if (i == 0) {
for (i=0;i<4;i++) {
form.dep.options[i].text="";
}
return;
}
form.dep.selectedIndex = 0;
switch (i) {
case 1 : var txt = new Array ('','Bas-Rhin','Haut-Rhin'); break;
case 2 : var txt = new Array ('Dordogne','Gironde','Landes','Lot-et-Garonne','Pyrénées-Atlantiques'); break;
case 3 : var txt = new Array ('Allier','Cantal','Haute-Loire','Puy-de-Dôme'); break;
}
form.dep.options[0].text="Département";
for (i=0;i<4;i++) {
form.dep.options[i+1].text=txt[i];
}
}
// -->
</SCRIPT>
</head>
<body>
<table border="5" align="center" cellpadding="1" cellspacing="4" class="table_n">
<br>
<tr>
<td align="center" bgcolor="#009900"><FONT size="6"><strong>Déposez votre annonce...</strong></FONT>
<strong>Vous proposez, vous recherchez ?*</strong>
<select name="type" id="type" class="eingabe">
<option value="" selected>Sélectionnez</option>
<option value="P">je propose</option>
<option value="R">je recherche</option>
</select>
</td >
</tr>
</table>
<br>
<table align="center">
</tr>
<tr>
<td align="center">
<strong>Quelle catégorie*</strong>
<select name="cat" id="cat" class="cat">
<option value="0">Choisissez</option>
<option value='1' style='background-color:#dcdcc3' disabled id='cat1' >-- VEHICULES --</option>
<option value='Voiture' id='cat2' >Cardiologie</option>
<option value='Tandem' id='cat3' >Pneumologie</option>
<option value='4' id='cat4' >Dermatologie</option>
<option value='5' id='cat5' >Hématologie</option>
</select></td>
</tr>
</table>
<br>
<table align="center">
<tr>
<td align="center">
<strong>Région*</strong>
<SELECT NAME="reg" onChange='Choix(this.form)'>
<option value="">Choisissez</option>
<option value="Alsace" <?php if(isset($_POST['reg']) && $_POST['reg'] == 'Alsace') echo 'selected';?>>Alsace</option>
<option value="Aquitaine" <?php if(isset($_POST['reg']) && $_POST['reg'] == 'Aquitaine') echo 'selected';?>>Aquitaine</option>
</select>
<align="center">
<strong>Département*</strong>
<SELECT NAME="dep">
<option value="">Choisissez</option>
<OPTION></OPTION>
<OPTION></OPTION>
<OPTION></OPTION>
<OPTION></OPTION>
<OPTION></OPTION>
</SELECT>
<strong> Code Postal</strong> <em>(facultatif)</em>  <INPUT type=text id="cp" name="cp"size="5">
</td>
</table>
<br>
<table border="2" align="center" cellpadding="3" cellspacing="3">
<td align="center"><strong>Titre de l'article*</strong> </td>
<td><INPUT type=text id="TitrA" name="TitrA"size="65"></td>
<tr>
<td align="center"><strong>Descriptif de l'article*</strong> </td>
<td><textarea type=text id="Detail" name="Detail" rows="5" cols="50"></textarea></td>
</tr>
</table>
<br>
<table border="2"align="center">
<TR>
<td align="center"><strong>Vous êtes*: un professionnel<INPUT type=radio name="status" value="Pro">
ou <INPUT type=radio name="status" value="Part">un particulier </TD>
</TR>
</table>
<table border="2" align="center" cellpadding="4" cellspacing="3">
<TR>
<td> <strong>Nom*</strong> <em>(ou pseudo)</em> 
<INPUT type=text name="pseudo"size="15">  
<strong>Email*</strong> 
<INPUT type=text name="mail"size="35">  
<strong> Tel</strong> <em>(facultatif, visible si entré )</em> 
<INPUT type=text name="tel"size="11"></td>
<br>
</TR>
</table>
<table border="5" align="center" cellpadding="1" cellspacing="4">
<br>
<TR>
<td align="center" bgcolor="#009900"><INPUT TYPE="submit" NAME="send" VALUE="Envoyer">
<input type="reset" name="reset" value="Effacer" /></TD>
</TR>
</table>
</form>