Guest User

multi form with input radio button

a guest
Feb 16th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. //index.php
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.  
  5. <title>Posting Multiple form dengan PHP</title>
  6. </head>
  7.  
  8. <body>
  9.  
  10.  
  11. <form method="get" action="#">
  12.     Jumlah form : <input type="text" size="5" name="jumlah" />
  13.     <input type="submit" name="btnJumlah" value="OK" />
  14. </form>
  15.  
  16.  
  17. <form method="post" action="proses.php">
  18. <?php
  19. $jumlah=isset($_GET['jumlah'])?
  20. $_GET['jumlah']:0;
  21.  
  22. if($jumlah){
  23.  
  24. for($i=0; $i<$jumlah; $i++){
  25. $nomor = $i + 1;
  26. echo $nomor .". ";
  27. ?>
  28.  
  29. jns kelamin : Pria <input type="radio" id="jk" name="jk[]" value="P" ></label> Wanita<input type="radio" id="jk" name="jk[]" value="W" ></label>
  30.  
  31. <br />
  32. <?php
  33. }
  34. //cetak tombol jika inputan lebih dari 0
  35.     }
  36.     if($jumlah >0){ ?><input type="submit" value="simpan" />
  37.     <?php } ?>
  38.  
  39. </form>
  40. </body>
  41. </html>
  42.  
  43. //proses.php
  44. <?php
  45.  
  46. //hitung jumlah form yang dikirim
  47. $jumlah = isset($_POST['jk']);
  48.  
  49.     echo "<h1>Cetak semua form</h1>";
  50.     for($i=0; $i<$jumlah; $i++){
  51.     $urut   = $i+1;
  52.    
  53.     $jk = $_POST['jk'][$i];
  54.  
  55.     //jika mau dimasukkan ke databases, silahkan buat query anda disini
  56.     echo $urut." - ".$jk."<br />";
  57.     }
  58.  
  59.  
  60.  
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment