IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Réaliser un formulaire avec des colonnes dynamiques


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2013
    Messages : 39
    Par défaut Réaliser un formulaire avec des colonnes dynamiques
    Salut les amis, j'ai besoin que vous me veniez en aide. J'ai réalisé le formulaire suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?php 
    if(isset($_POST['submit']))
    {
    	$nomass = htmlentities (trim ($_POST['nomass']));
    	$preass = htmlentities (trim ($_POST['preass']));
    	$nomconj = htmlentities (trim ($_POST['nomconj']));
    	$preconj = htmlentities (trim ($_POST['preconj']));
    	$nbreenft = htmlentities (trim ($_POST['nbreenft']));
    	if (($nomass<>'') AND ($preass<>'') AND ($nomass<>'') AND ($preconj<>'') AND ($nbreenft<>'') )
    	{	$log = mysql_query ("SELECT * FROM assure WHERE nomprojet='$nomprojet' "); 
    		$cols = mysql_num_rows($log);
    		if($cols==0)
    		{
    			mysql_query ("INSERT INTO assure (idass, nomass, preass, nomconj, preconj, nbreenft)  VALUES ('', '$nomass', '$preass', '$nomconj', '$preconj', '$nbreenft') ");
    			die (" <br/>Les données saisies ont été bien enregistrées.  <a href='donneedebaseprojet.php'> <strong> Précédent </strong> </a>     <a href='donneedebasesection.html'> <strong> Suivant </strong> </a>");
    		} else "Ce projet existe déjà !!! Veuillez consulter la liste des <a href='#'> <strong> projets déjà réalisés.  </strong> </a>";	
    	}else echo "Veuillez renseigner tous les champs SVP.";
    }
    ?>
     
    <form method="post" action="enregistrement_infos.php">
    	<p>
    		<table border="1" align="center">
     
    			<tr> <th>NOM ASSURE(E) </th> 
    				<td><input type="text" name="nomass" id="nomass" size="32" maxlength="255" /> </td> 
    			</tr>
     
    			<tr>	<th>PRENOMS ASSURE(E) </th> 
    				<td><input type="text" name="preass" id="preass" size="32" maxlength="255" /> </td> 
    			</tr>
     
    			<tr>  <th>NOM CONJOINT(E)  </th> 
    				<td><input type="text" name="nomconj" id="nomconj" size="32" maxlength="255" /> </td> 
    			</tr>
     
    			<tr> <th>PRENOMS CONJOINT(E) </th> 
    				<td><input type="text" name="preconj" id="preconj" size="32" maxlength="255" /> </td> 
    			</tr>
     
    			<tr> <td colspan="">NOMBRE D'ENFANTS</td>
    				<td><input type="text" name="nbreenft" id="nbreenft" size="10" maxlength="2" /> </td>
    			</tr>
     
    			<tr>
    				<td colspan="2"><input type="submit" value="VALIDER" name="submit" id="boutonvalider" />  </td>
    			</tr>
     
    		</table>
    	</p>			
    	</form>
    Après validation de ce formulaire, une autre formulaire devra être affiché en tenant compte du nombre d'enfants saisi. Ci dessous le code de cet autre formulaire :
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <form>
    	<tr> <td colspan="2">TYPE ASSURANCE </td>
    		<td>
    			<select name="typassur" id="typassur" >
    				<option value="toutrisk">Tout Risque</option>
    				<option value="maladie">Maladie</option>
    				<option value="accident">Accident</option>
    			</select>
    		</td>
    	</tr>
     
    	<tr>
    		<td colspan="2">NOM </td>
    		<td><input type="text" name="nom" id="nom" size="32" maxlength="255" /> </td>
    	</tr>
     
     
    	<tr> <td colspan="2">PRENOMS </td>
    		<td><input type="text" name="prenom" id="prenom" size="32" maxlength="255" /> </td>
    	</tr>
     
    	<tr> <td colspan="2">DATE DE NAISSANCE</td>
    		<td><input type="date" name="datnaiss" id="datnaiss" size="32" maxlength="255" /> </td>
    	</tr>
     
    	<tr> <td colspan="2">LIEU DE NAISSANCE</td>
    		<td><input type="text" name="lieunaiss" id="lieunaiss" size="32" maxlength="255" /> </td>
    	</tr>
     
    	<tr> <td colspan="2">SEXE </td>
    		<td>
    			<select name="sexe" id="sexe" >
    				<option value="Masculin">Masculin</option>
    				<option value="Feminin">Feminin</option>
    			</select>
    		</td>
    	</tr>
     
    	<tr>
    		<td colspan="3"><input type="submit" value="ENREGISTRER" name="submit" id="enregistrer" />  </td>
    	</tr>
     
    	</table>	
    </form>

  2. #2
    Membre expérimenté
    Avatar de crozet.magenta
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2012
    Messages
    208
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2012
    Messages : 208
    Par défaut
    et ?

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2013
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2013
    Messages : 28
    Par défaut
    D'abord je crois que tu devrais mettre une liste déroulante pour le nombre d'enfant, ça te faciliterais la tâche. Sinon, tu dois vérifier que l'utilisateur a bien mis un chiffre dans ta boite texte (petit script js).

    Disons qu'on a entré 3 enfants sa ne fonctionnera pas, il faut absolument un chiffre... À ta place je préférerais la liste déroulante.

    Scénario 1:

    Quelqu'un choisis 3 sur la liste déroulante, il passe la value 3 vers l'autre page dans $Ta_Variable.

    Tu te fais un petit for ($i = 1; $i <= $Ta_Variable; $i++) { // ton autre formulaire ici }.

    Évidement si tu veux avoir de belle colonnes tu pourrais mettre le tout dans un div avec une classe en commun et t'amuser dans les styles css

  4. #4
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2013
    Messages : 39
    Par défaut
    Salut cher ami, jai testé ta proposition mais ça ne passe pas.

  5. #5
    Membre confirmé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2013
    Messages
    28
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2013
    Messages : 28
    Par défaut
    Quelle est le message derreur..?

    Le code de tes 2 pages ressemble a quoi?

  6. #6
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2013
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2013
    Messages : 39
    Par défaut
    Salut TiMasse, sincères excuses pour ce silence.
    Voici le message d'erreur qui est affichér :
    "Parse error: syntax error, unexpected '<' in C:\Program Files\EasyPHP-12.1\www\assurance\assurance.php on line 95"
    Et ci-dessous le code que j'ai réalisé :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
    	<link rel="stylesheet" href="stylesss.css" />
            <title>Titre</title>
        </head>
     
        <body>
     
    <?php 
    	if(isset($_POST['submit']))
    	{
    		$nomass = htmlentities (trim ($_POST['nomass']));
    		$preass = htmlentities (trim ($_POST['preass']));
    		$nomconj = htmlentities (trim ($_POST['nomconj']));
    		$preconj = htmlentities (trim ($_POST['preconj']));
    		$nbreenft = htmlentities (trim ($_POST['nbreenft']));
     
    			if (($nomass<>'') AND ($preass<>'') AND ($nomass<>'') AND ($preconj<>'') AND ($nbreenft<>''))
     
    			{	
    				$connect = mysql_connect('localhost', 'root', '') or die ('Impossible de se connnecter à la Base de Données');
    				$mabd = mysql_select_db ('assurance');
    				$gra = mysql_query ("SELECT * FROM assure WHERE nomass='$nomass' "); 
    				$tra = mysql_num_rows($gra);
     
    					if($tra==0)
    					{
    						mysql_query ("INSERT INTO assure (idass, nomass, preass, nomconj, preconj, nbreenft)  VALUES ('', '$nomass', '$preass', '$nomconj', '$preconj', '$nbreenft') ");
    						die (" <br/>Les données saisies ont été bien enregistrées. <a href='assurance.php'> <strong> Retour </strong> </a>");
     
    					} else "Cet assuré existe déjà dans la BD.";	
     
    			}else echo "Veuillez renseigner tous les champs SVP.";
    	}
     
    ?>
     
    <form method="post" action="assurance.php">
    	<p>
    		<table border="1" align="center">
     
    			<tr> <th>NOM ASSURE(E) </th> 
    				<td><input type="text" name="nomass" id="nomass" size="32" maxlength="255" /> </td> 
    			</tr>
     
    			<tr>	<th>PRENOMS ASSURE(E) </th> 
    				<td><input type="text" name="preass" id="preass" size="32" maxlength="255" /> </td> 
    			</tr>
     
    			<tr>  <th>NOM CONJOINT(E)  </th> 
    				<td><input type="text" name="nomconj" id="nomconj" size="32" maxlength="255" /> </td> 
    			</tr>
     
    			<tr> <th>PRENOMS CONJOINT(E) </th> 
    				<td><input type="text" name="preconj" id="preconj" size="32" maxlength="255" /> </td> 
    			</tr>
     
    			<tr> <th>NOMBRE D'ENFANTS</th>
    				<td> <select name="nbreenft" id="nbreenft" >
    							<option value="1" selected="selected" >1</option>
    							<option value="2" >2</option>
    							<option value="3" >3</option>
    							<option value="4" >4</option>
    							<option value="5" >5</option>
    							<option value="6" >6</option>
    							<option value="7">7</option>
    							<option value="8" >8</option>
    							<option value="9" >9</option>
    							<option value="10" >10</option>
    							<option value="11" >11</option>
    							<option value="12" >12</option>
     
    						</select>
    				</td>
    			</tr>
     
    			<tr>
    				<th colspan="2"><input type="submit" value="VALIDER" name="submit" id="boutonvalider" />  </th>
    			</tr>
     
    		</table>
    	</p>			
    	</form>
    ?>
     
     
    <table border="1" align="center">
    <?php 
     
    for ($i=1; $i<=$nbreenft; $i++)
    	{ 
    	<tr>
    		<td colspan="2"></td>
    		<?php echo'<td colspan="">ENFANT N° ......</td>'; ?>
    	</tr>
     
    	<form>
    	<tr> <td colspan="2">TYPE ASSURANCE </td>
    		<?php echo'<td>
    			<select name="typassur" id="typassur" >
    				<option value="toutrisk">Tout Risque</option>
    				<option value="maladie">Maladie</option>
    				<option value="accident">Accident</option>
    			</select>
    		</td>'; ?>
    	</tr>
     
    	<tr>
    		<td colspan="2">NOM </td>
    		<?php echo'<td><input type="text" name="nom" id="nom" size="32" maxlength="255" /> </td>'; ?>
    	</tr>
     
     
    	<tr> <td colspan="2">PRENOMS </td>
    		<?php echo'<td><input type="text" name="prenom" id="prenom" size="32" maxlength="255" /> </td>'; ?>
    	</tr>
     
    	<tr> <td colspan="2">DATE DE NAISSANCE</td>
    		<?php echo'<td><input type="date" name="datnaiss" id="datnaiss" size="32" maxlength="255" /> </td>'; ?>
    	</tr>
     
    	<tr> <td colspan="2">LIEU DE NAISSANCE</td>
    		<?php echo'<td><input type="text" name="lieunaiss" id="lieunaiss" size="32" maxlength="255" /> </td>'; ?>
    	</tr>
     
    	<tr> <td colspan="2">SEXE </td>
    		<?php echo'<td>
    			<select name="sexe" id="sexe" >
    				<option value="Masculin">Masculin</option>
    				<option value="Feminin">Feminin</option>
    			</select>
    		</td>'; ?>
    	</tr>
     
    	<tr>
    		<td colspan="3"><input type="submit" value="ENREGISTRER" name="submit" id="enregistrer" />  </td>
    	</tr>
    	 }
    ?>
    	</table>	
    	</form>
    </body>
    </html>

Discussions similaires

  1. Zone d'impression dynamique avec des colonnes masquées
    Par target111 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 24/03/2013, 15h16
  2. Réponses: 4
    Dernier message: 25/06/2012, 14h13
  3. DataTable avec des colonnes dynamiques
    Par PrinceDeLu dans le forum JSF
    Réponses: 5
    Dernier message: 15/04/2011, 10h54
  4. Un tableau avec des colonnes dynamiques
    Par Cronycs dans le forum Struts 1
    Réponses: 5
    Dernier message: 07/06/2007, 13h38
  5. Réponses: 2
    Dernier message: 17/11/2006, 07h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo