Bonjour à tous,

j'ai un formulaire avec un input. Je peux rajouter des lignes supplémentaires d'inputs grâce à un bouton associé à une fonction javascript. Mon problème est que lorsque je soumets mon formulaire, seule la ligne input d'origine passe en $_POST.

mon code est classique. un choix permet d'afficher un div ou une autre.
Dans une des div, deux boutons + et - permettent de rajouter des lignes de formulaire. le bouton submit fonctionne mais ne passe que les $_POST['blabla_1'] mais pas les nouveaux inputs 2,3 et 4 (ce que je vérifie par une boucle foreach($_POST...) à la fin du script.

Ma question: Comment récupérer les valeurs $_POST de ces nouveaux inputs créés par javascript pour les traiter en php/mysql. J'imagine que c'est un problème client-serveur et que je devrais probablement passer par ajax...? Et là j'ai besoin de vous...

Merci d'avance.
Voici mon code:
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
 
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  <title>ajoutprimer.php</title>
 
<!-- MON CSS ------------------------------------ -->  
<style type="text/css">
div#primergenotyping
{
width:1270px;
display:none;
margin:auto;
padding: 0;
background-color: #99aaee;
}
div#primercommon
{
width:250px;
margin: auto ;
display:block;
padding: 0;
background-color: #aa99ee;
}
div#primerqpcr
{
width:1150px;
display:none;
margin:auto;
padding: 0;
background-color: #99CCCC;
}
</style>
 
 
<!-- FONCTION CHOIX AFFICHAGE DIV QPCR ou GENOTYPING   -->
<script type="text/javascript">
 
function choix(btn,champ1,champ2)
{
if (btn.id == "radiogenotyping"){
afficher(champ1,true);
afficher(champ2,false);
}
else if (btn.id == "radioqpcr"){
afficher(champ2,true);
afficher(champ1,false);
}
}
 
function afficher (div, affiche) {
if (affiche){
document.getElementById(div).style.display="block";
}
else {
document.getElementById(div).style.display="none";
}
}
 
</script>
 
 
<!-- FONCTION AJOUT RETRAIT CHAMP PRIMER DANS DIV PRIMERGENOTYPING -->
<script language="javascript">
var i = 1
function create_champ() 
	{
	i++;
	if (i<5){
	document.getElementById('ligne_'+i).innerHTML += '<th>primers '+i+' </th><td><input type="text" name="newidF'+i+'" size="6" maxlength="4"/></td><td><input type="text" name="oldidF'+i+'" size="6" maxlength="30"/></td><td><input type="text" name="F'+i+'" size="30" maxlength="30"/></td><td width="35"></td><td><input type="text" name="newidR'+i+'" size="6" maxlength="4"/></td><td><input type="text" name="oldidR'+i+'" size="6" maxlength="30"/></td><td><input type="text" name="R'+i+'" size="30" maxlength="30"></td><td width="35"></td><td><input type="text" name="A'+i+'" size="5" maxlength="5"></td><td><input type="text" name="TM'+i+'" size="5" maxlength="5"></td>';
	}
	else{i--;}
	}
 
function suppr()
	{
	if(i>4){i=4};
	document.getElementById("ligne_"+i).innerHTML="";
	i--;}
</script>
 
</head>
 
 
<!-- ********************************************************** -->
<body>
 
 
<!--  DIV COMMON ---------------- -->
<div id="primercommon">
 
<form name="ajoutprimer" action="Nouveau2.php" method="post">
  user: <input type="text" name="user" readonly="readonly" value="<?php echo $_SESSION['login']; ?>">
<br><br>
<center><strong>For:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	</strong></center>
<br>
<label>Genotyping </label>
<input type="radio" name="use" id="radiogenotyping" value="genotyping" onclick="choix(this,'primergenotyping', 'primerqpcr')";>********* 
<label>Q-PCR </label>
<input type="radio" name="use" id="radioqpcr" value="qpcr" onclick="choix(this,'primergenotyping', 'primerqpcr')";>
<br>
</div>
<!--  DIV COMMON ---------------- -->
 
 
<!--  DIV GENOTYPING ---------------- -->
<div id="primergenotyping">
<center> colony: <input type="text" name="colony"> </center> <br>
 
<table>
  <tbody>
    <tr>
      <th></th>
      <th>new id</th>
      <th align="center">old id<br> or name</th>
      <th>primer forward 5' -&gt; 3'</th>
      <th width="35"></th>
      <th>new id</th>
      <th align="center">old id<br> or name</th>
      <th>primer reverse 5' -&gt; 3'</th>
      <th width="35"></th>
      <th>Amplicon <br> (bp) </th>
      <th>Melting <br>Temp.(°) </th>
      <th align="center"> Add/Remove<br> Primers</th>	
    </tr>
    <tr>
      <th>primers 1 </th>
      <td><input type="text" name="newidF1" size="6" maxlength="4"/> </td>
      <td><input type="text" name="oldidF1" size="6" maxlength="30"/> </td>
      <td><input type="text" name="F1" size="30" maxlength="30"/> </td>
      <td width="35"></td>
      <td><input type="text" name="newidR1" size="6" maxlength="4"/> </td>
      <td><input type="text" name="oldidR1" size="6" maxlength="30"/> </td>
      <td><input type="text" name="R1" size="30" maxlength="30"> </td>
      <td width="35"></td>
      <td><input type="text" name="A1" size="5" maxlength="5"> </td>
      <td><input type="text" name="TM1" size="5" maxlength="5"> </td>
      <Td rowspan="4" align="center" valign="middle"> <input type="button" value="+" onclick="create_champ()"> <input type="button" value="-" onclick="suppr()"> </Td>
    </tr>
    <tr id="ligne_2"></tr>
	<tr id="ligne_3"></tr>
	<tr id="ligne_4"></tr>
  </tbody>
</table>
<br>
adds: <input type="text" name="add" size="100">
 
</div>
<!-- FIN DIV GENOTYPING ---------------- -->
 
 
 
<!--  DIV QPCR ---------------- -->
<div id="primerqpcr">
 
<center>
 gene: <input type="text" name="gene"> <br>
From: <input type="text" name="gene"> To: <input type="text" name="gene">
</center> <br>
 
<table>
  <tbody>
    <tr>
      <th></th>
      <th>new id</th>
      <th align="center">old id<br> or name</th>
      <th>primer forward 5' -&gt; 3'</th>
      <th width="35"></th>
      <th>new id</th>
      <th align="center">old id<br> or name</th>
      <th>primer reverse 5' -&gt; 3'</th>
      <th width="35"></th>
      <th>Amplicon <br> (bp) </th>
      <th>Melting <br>Temp.(°) </th>
 
    </tr>
    <tr>
      <th>primers  </th>
      <td><input type="text" name="newidF0" size="6" maxlength="4"/> </td>
      <td><input type="text" name="oldidF0" size="6" maxlength="30"/> </td>
      <td><input type="text" name="F0" size="30" maxlength="30"/> </td>
      <td width="35"></td>
      <td><input type="text" name="newidR0" size="6" maxlength="4"/> </td>
      <td><input type="text" name="oldidR0" size="6" maxlength="30"/> </td>
      <td><input type="text" name="R0" size="30" maxlength="30"> </td>
      <td width="35"></td>
      <td><input type="text" name="A0" size="5" maxlength="5"> </td>
      <td><input type="text" name="TM0" size="5" maxlength="5"> </td>
    </tr>
 
  </tbody>
</table>
<br> 
adds: <input type="text" name="add" size="100">
 
</div>
 <!-- FIN DIV QPCR ---------------- -->
 
<!-- FIN DU FORMULAIRE AVEC LE SUBMIT  ------------ -->
<input type="submit" name="envoi" value="envoiFORM">
</form> 
 
 
<!-- BOUCLE POUR VERIFIER LE PASSAGE DES DONNEES $_POST -->
<?php
foreach($_POST as $field => $value)
        {echo "champ: ".$field."<br>value: ".$value."<br> ------ <br>";}
?>
 
 
</body>
</html>