Aller au contenu

gael_info

Membre
  • Compteur de contenus

    2
  • Inscrit(e) le

  • Dernière visite

Réputation sur la communauté

0 Neutre
  1. en fait le problème n'est pas que ça ne marche pas. Le formulaire apparait nickel, mais je n'arrive pas à récupérer ce que je rentre dans ce formulaire dans le fichier sitephp.php. Pour reprendre le 1er exemple de bibi arnaud, c'est comme si le champ texte "société" ne pouvait être récupéré dans valid_contact.php
  2. Bonjour, merci d'avoir répondu, car comme bibi arnaud, ce problème m'a pris 1 semaine avant de la résoudre grâce à ce topic. Cependant un problème subsiste: Je voudrai récupérer les données du nouveau formulaire, mais je n'y arrive pas avec cette méthode. Tout ce passe comme si les noms des champs crées ne se transmettaient à la page php. Voici les codes: formulaire.html: <form action="sitephp.php" method="post" name="form1" id="form1"> <table align="left" id="table_select"> <tr> <td> <select name="selec" id="selec" onclick="affiche_text_reponse(form)"> <option></option> <option value="1" >CTD <option value="2">Hydrophone <option value="3">ADCP <option value="4">Fluorometer <option value="5">Sediment Sampler <option value="6"> Other </select> <!--add serial number, or a sensor which is not in the previous menu, or information on the sensor--> <input name="sensor_name2" type="text style7" id="sensor_name2" size="60"> </td> </tr> <tr> <td> <div class="bodytext style7" colspan="2" id="D_INPUT" name="D_INPUT"></div> </td> </tr> </table> </form> codejava script: function affiche_text_reponse(form1) { var Obj = document.getElementById( 'D_INPUT'); // Recup du DIV var Html = ""; // le nouveau contenu var nb_rep = eval(form1.selec.value); if (nb_rep == 1) { Html += "<form method='post' name='CTD_mesures' action='sitephp.php'> <table width=\"100%\" cellpading=0 cellspacing=0> <tr> <td width=100>Conductivity:</td><td><input name='Conductivity' id='Conductivity' size='20' type='text'></td> </tr> <tr> <td width=100>Temperature:</td><td><input name='Temperature' id='Temperature' size='20' type='text'></td> </tr> <tr> <td width=100>Pressure:</td><td><input name='Pressure' id='Pressure' size='20' type='text'></td> </tr> </table> </form>"; } else { Html += "choose an other sensor"; } Obj.innerHTML = Html; // ecriture dans le DIV } Code php sitephp.php: <?php $cond = $_POST['Conductivity']; $temp = $_POST['Temperature']; $pres= $_POST['Pressure']; //creation of a new DOM document $document = new DomDocument; //write the new XML element in a unclouded presentation, instead of on a single line $document->preserveWhiteSpace = FALSE; $document->formatOutput = TRUE; //load the XML presentation $document->load("tableau_eso.xml"); // creating new nodes from the datas received // in order to build a new array line $sensor = $document->createElement("sensor" ); $document->documentElement->appendChild($sensor); $sens_type = $document->createElement("sensor_number","$sensor_type" ); $sens_type= $sensor->appendChild($sens_type); $cal = $document->createElement("calibrationdate","$caldate" ); $cal = $sensor->appendChild($cal); $weight1 = $document->createElement("weight","$weight" ); $weight1 = $sensor->appendChild($weight1); $cond1 = $document->createElement("conductivity","$cond" ); $cond1 = $sensor->appendChild($cond1); $temp1 = $document->createElement("temperature","$temp" ); $temp1 = $sensor->appendChild($temp1); $pres1 = $document->createElement("pressure","$pres" ); $pres1 = $sensor->appendChild($pres1); // writing new nodes in the XML file $document->save("tableau_eso.xml"); // Reading an XML file function lit_xml($fichier,$item,$champs) { // reading the file if($chaine = _AT_implode("",@file($fichier))) { // exploding on <item> $tmp = preg_split("/<\/?".$item.">/",$chaine); // for each <item> for($i=1;$i<sizeof($tmp)-1;$i+=2) // reading the domain wanted <champ> foreach($champs as $champ) { $tmp2 = preg_split("/<\/?".$champ.">/",$tmp[$i]); // add to board $tmp3[$i-1][] = @$tmp2[1]; } // return the board return $tmp3; } } // Exemple : $xml = lit_xml("tableau_eso.xml","sensor",$tab = array("sensor_number","calibrationdate","weight","conductivity","temperature","pressure")); // how many members are there in the array $var_count = count($tab); // print it echo "<table border>"; foreach($xml as $row) { ?> <html> <body> <!--build the board with all datas received, since the beginning--> <!--.$row[] is the line of the array which will be in the board --> <tr> <font size=2 color=gray></font> <?php for($i = 0;$i < $var_count; $i++) { echo "<td align=center>".$row[$i]."</td>"; }?> </tr> </body> </html> <?php } echo "</table>" ; ?> Ce code php récupère un tableau via un fichier XML et l'implémente à chaque nouvelle saisie de formulaire Merci d'avance pour votre aide P.S, je sais que dans le code javascript, il faut mettre la réponse sur une seule ligne, mais je l'ai mis comme ça sur ce message afin de faciliter la compréhension
×
×
  • Créer...