Bonjour à tous,
j'aimerais savoir comment en php, remplir les champs d'un formulaire, suite au choix d'une option dans un select (liste déroulante).
Vu dans mon exemple, un fournisseur est enregistré dans la BD avec son nom, son contact et son email.
J'aimerais donc savoir comment au choix d'un fournisseur, les champs contact et email se remplissent automatiquement. Merci beaucoup de votre aide.
Mon code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Document sans titre</title> <link href="Content/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css"> <link rel="stylesheet" href="style.css" /> </script> <style type="text/css"> <!-- .Style1 { font-size: 24px; color: #FFFF00; font-weight: bold; font-style: italic; } span {text-decoration: blink;} .Style10 {font-size: 14px; color: #FFFF00; font-weight: bold; } .Style13 { color: #000099; font-weight: bold; } .Style18 {color: #000000; font-weight: bold; } --> </style> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <link rel="stylesheet" href="/resources/demos/style.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script> $( function() { $( "#datepicker" ).datepicker(); } ); </script> </head> <body> <?php session_start() ?> <?php // Remplir liste déroulante à partir de la base de données require('config.php'); $req = "SELECT * FROM fournisseur ORDER BY nom ASC"; $result = mysql_query( $req, $connect) or die( "Exécution requête impossible."); mysql_close( $connect); $ld = "<SELECT NAME='select' type=submit>"; $ld .= "<OPTION VALUE=0>Choisissez</OPTION>"; while ( $row = mysql_fetch_array( $result)) { $nom = $row["nom"]; $ld .= "<OPTION selected VALUE='$nom'>$nom</OPTION>"; } $ld .= "</SELECT>"; ; ?> <?php // Remplir liste déroulante à partir de la base de données require('config.php'); $req1 = "SELECT * FROM nourriture ORDER BY design ASC"; $result1 = mysql_query( $req1, $connect) or die( "Exécution requête impossible."); mysql_close( $connect); $ld1 = "<SELECT NAME='select2'>"; $ld1 .= "<OPTION VALUE=>Choisissez</OPTION>"; while ( $row1 = mysql_fetch_array( $result1)) { $design = $row1["design"]; $ld1 .= "<OPTION selected VALUE='$design'>$design</OPTION>"; } $ld1 .= "</SELECT>"; ; ?> <table width="943" align="center"> <tr> <td width="935" height="71" bgcolor="#000099"><div align="center" class="Style1">* RMB * </div> <div align="center"></div></td> </tr> <tr> <td bgcolor="#FFFF00"></td> </tr> <tr> <td height="12" bgcolor="#FFFF00"><a href="index.php"><img src="photoshop/optimiser-page-accueil-blog.png" width="21" height="21" border="0" align="left" /></a> <div align="center" class="Style13">COMMANDER UN ARTICLE </div></td> </tr> <tr> <td height="490" valign="top" background="photoshop/font.jpg" class="font"><div align="center"> <form id="form1" name="form1" method="post" action=""> <table width="500" border="0"> <tr> <td width="192">Désignation</td> <td width="298"><label><?php print $ld1; ?> </label></td> </tr> <tr> <td>Quantité</td> <td><label> <input type="text" name="textfield2" /> </label></td> </tr> <tr> <td>Fournisseur</td> <td><?php print $ld; ?></td> </tr> <tr> <td>Contact</td> <td><label> <input type="text" name="textfield" /> </label></td> </tr> <tr> <td>Email</td> <td><label> <input type="text" name="textfield3" /> </label></td> </tr> <tr> <td>Date de livraison </td> <td><label> <input name="livraison" type="text" id="datepicker" /> </label></td> </tr> <tr> <td colspan="2"><label> <div align="center"> <input name="commander" type="submit" id="commander" value="COMMANDER" /> </div> </label></td> </tr> </table> <?php if (isset($_POST['select2'])) { $choix = $_POST['select2']; echo "".$choix; } if (isset($_POST['select'])) { $choix = $_POST['select']; echo "".$choix; } if(isset($_POST['commander'] )) { } ?> </form> </div> </td> </tr> <tr> <td height="10" bgcolor="#000099"><div align="center"><span class="Style10"><marquee>* RMB * * RMB * </marquee> </span></div></td> </tr> </table> <p> </p> </body> </html>
Afficher la suite