Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //index.php
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Posting Multiple form dengan PHP</title>
- </head>
- <body>
- <form method="get" action="#">
- Jumlah form : <input type="text" size="5" name="jumlah" />
- <input type="submit" name="btnJumlah" value="OK" />
- </form>
- <form method="post" action="proses.php">
- <?php
- $jumlah=isset($_GET['jumlah'])?
- $_GET['jumlah']:0;
- if($jumlah){
- for($i=0; $i<$jumlah; $i++){
- $nomor = $i + 1;
- echo $nomor .". ";
- ?>
- jns kelamin : Pria <input type="radio" id="jk" name="jk[]" value="P" ></label> Wanita<input type="radio" id="jk" name="jk[]" value="W" ></label>
- <br />
- <?php
- }
- //cetak tombol jika inputan lebih dari 0
- }
- if($jumlah >0){ ?><input type="submit" value="simpan" />
- <?php } ?>
- </form>
- </body>
- </html>
- //proses.php
- <?php
- //hitung jumlah form yang dikirim
- $jumlah = isset($_POST['jk']);
- echo "<h1>Cetak semua form</h1>";
- for($i=0; $i<$jumlah; $i++){
- $urut = $i+1;
- $jk = $_POST['jk'][$i];
- //jika mau dimasukkan ke databases, silahkan buat query anda disini
- echo $urut." - ".$jk."<br />";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment