Champs form optionnels
Posté : 05 août 2006, 18:34
Bonjour,
J'ai réalisé un site avec le CMS Artiloo que je trouve pratique, il est visible à cette adresse :http://www.iprp-ist.info.
J'ai un soucis pour une page de saisie de données pour alimenter la base de données. Tous les champs du form ne sont pas obligatoires dans la base mais on est obligé de saisir quelque chose sous peine de tout recommencer. C'est très chiant.
Voici le code de la page:
Merci de m'indiquer la marche à suivre
J'ai réalisé un site avec le CMS Artiloo que je trouve pratique, il est visible à cette adresse :http://www.iprp-ist.info.
J'ai un soucis pour une page de saisie de données pour alimenter la base de données. Tous les champs du form ne sont pas obligatoires dans la base mais on est obligé de saisir quelque chose sous peine de tout recommencer. C'est très chiant.
Voici le code de la page:
<?php require_once('../Connections/afist.php'); ?>
<?php
if (!$_SESSION['SESSION_USER']) {
header(" Location : ../outils/erreur.php?ec=2");
exit();
}
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO afist_etude (id_etude, titre, auteurs, secteur_act, nb_salaries, postes, resum, id_danger, methode, outils, solutions, evaluation, type_supp, theme, `public`, autre) ".
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_etude'], "int"),
GetSQLValueString($_POST['titre'], "text"),
GetSQLValueString($_POST['auteurs'], "int"),
GetSQLValueString($_POST['secteur_act'], "text"),
GetSQLValueString($_POST['nb_salaries'], "int"),
GetSQLValueString($_POST['postes'], "text"),
GetSQLValueString($_POST['resum'], "text"),
GetSQLValueString($_POST['id_danger'], "int"),
GetSQLValueString($_POST['methode'], "text"),
GetSQLValueString($_POST['outils'], "text"),
GetSQLValueString($_POST['solutions'], "text"),
GetSQLValueString($_POST['evaluation'], "text"),
GetSQLValueString($_POST['type_supp'], "text"),
GetSQLValueString($_POST['theme'], "text"),
GetSQLValueString($_POST['public'], "text"),
GetSQLValueString($_POST['autre'], "text"));
mysql_select_db($database_afist, $afist);
$Result1 = mysql_query($insertSQL, $afist) or die(mysql_error());
$insertGoTo = "/wrapper/pages/etude_insert";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_afist, $afist);
$query_etude = "SELECT * FROM afist_etude";
$etude = mysql_query($query_etude, $afist) or die(mysql_error());
$row_etude = mysql_fetch_assoc($etude);
$totalRows_etude = mysql_num_rows($etude);
mysql_select_db($database_afist, $afist);
$query_danger = "SELECT * FROM afist_etude_danger";
$danger = mysql_query($query_danger, $afist) or die(mysql_error());
$row_danger = mysql_fetch_assoc($danger);
$totalRows_danger = mysql_num_rows($danger);
mysql_select_db($database_afist, $afist);
$query_user = "SELECT id_annulien, sigle, Anomlien, Amail FROM afist_adresse_annulien";
$user = mysql_query($query_user, $afist) or die(mysql_error());
$row_user = mysql_fetch_assoc($user);
$totalRows_user = mysql_num_rows($user);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="file:///C|/Program%20Files/EasyPHP1-7/www/afist/templates/temp/patchwork/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table width="100%" align="center">
<tr valign="top">
<td width="20%" align="right" nowrap>Titre:</td>
<td><input type="text" name="titre" value="" size="70"></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Auteur:</td>
<td>
<select name="auteurs">
<?php
do {
?>
<option value="<?php echo $row_user['id_annulien']?>" ><?php echo $row_user['Anomlien']?></option>
<?php
} while ($row_user = mysql_fetch_assoc($user));
?>
</select> </td>
<tr valign="top">
<td width="20%" align="right" nowrap>Secteur d'activité:</td>
<td><input type="text" name="secteur_act" value="" size="70"></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Nombre de salariés:</td>
<td><input type="text" name="nb_salaries" value="" size="70"></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Postes:</td>
<td><input type="text" name="postes" value="" size="70"></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Résumé:</td>
<td><textarea name="resum" cols="55" rows="4"></textarea></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Type de risque identifié :</td>
<td>
<select name="id_danger">
<?php
do {
?>
<option value="<?php echo $row_danger['id_danger']?>" ><?php echo $row_danger['type_danger']?></option>
<?php
} while ($row_danger = mysql_fetch_assoc($danger));
?>
</select> </td>
<tr valign="top">
<td width="20%" align="right" nowrap>Methode utilisée:</td>
<td><input type="text" name="methode" value="" size="70"></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Outils:</td>
<td><input type="text" name="outils" value="" size="70"></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Solutions:</td>
<td><textarea name="solutions" cols="55" rows="3"></textarea></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Evaluation:</td>
<td><textarea name="evaluation" cols="55" rows="3"></textarea></td>
</tr>
<tr valign="top">
<td align="right" nowrap><div align="left" class="menutitre"></div></td>
<td align="right" nowrap><div align="left"><span class="menutitre">Support d'information</span></div></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Type de support:</td>
<td><input type="text" name="type_supp" value="" size="70"></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Theme du support:</td>
<td><input type="text" name="theme" value="" size="70"></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Public:</td>
<td><input type="text" name="public" value="" size="70"></td>
</tr>
<tr valign="top">
<td align="right" nowrap> </td>
<td align="right" nowrap><div align="left" class="menutitre">Informations
complémentaires</div></td>
</tr>
<tr valign="top">
<td width="20%" align="right" nowrap>Autre:</td>
<td><textarea name="autre" cols="55" rows="3"></textarea></td>
</tr>
<tr valign="top">
<td colspan="2" align="right" nowrap><div align="center">
<input type="submit" value="Insérer l'enregistrement">
</div></td>
</tr>
</table>
<input type="hidden" name="id_etude" value="">
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($etude);
mysql_free_result($danger);
mysql_free_result($user);
?>
Est-ce que si je remplace les valeurs %s en début de code php j'otiendrai la possibilité de ne pas remplir ces champs?Merci de m'indiquer la marche à suivre