Creating Simple Input and Output Forms with PHP

In this article I want to provide a tutorial on how to create input and output forms with PHP without a database.

What is Form? In a website form usually functions to receive data input from users or website visitors then the data will be stored and will appear again if we need it. Form in general is an interface that functions to collect user data.

An ordinary input output form uses a database as data storage. But in this simple tutorial I will use an Array instead of a database which functions to temporarily store data.

Without any length, just go to the tutorial.

How to Create Simple Input and Output Forms with PHP

  • Open your text editor software.
  • First we will create an input form display first
<html>
 <form method="POST" name="frmpost" action="">
  <table align="center" border="1" cellpadding="0" cellspacing="0"> 
    <tr align="center"><td><h2> <b>Masukan Biodata Kalian</b></h2></td></tr>
    <tr> 
      <td>
      <table width="450" border="0" cellpadding="0" cellspacing="10" align="center">
        <tr>
          <td>Nama</td>
          <td> : </td>
          <td><input name="nama[]" type="text" size="40" /></td>
        </tr>
        <tr>
          <td>Tempat Tgl Lahir</td>
          <td> : </td>
          <td><input name="tgl[]" type="text" size="40" /></td>
        </tr>
        <tr>
          <td>Jenis Kelamin</td>
          <td> : </td>
          <td>
            <input type="radio" name="jk" value="Laki - Laki"><label for="laki">Laki - Laki</label>
            <input type="radio" name="jk" value="Perempuan"><label for="Perempuan">Perempuan</label>
          </td>
        </tr>
        <tr>
          <td>Hobi</td>
          <td> : </td>
          <td><input name="hobi[]" type="text" size="40" /></td>
        </tr>
        <tr>
          <td   colspan="4" align="center"><input type="submit" name="btnOk" value="Simpan" /></td>
        </tr>
      </table>
      </td>
    </tr>
  </table>
</form>
</html>

Note: At the top of the form making uses the POST method which functions to send data directly, which is different from the GET method which functions to send indirect data so that the data is visible in the URL. Where the date [] is an array variable that functions to store data. And later it will be called back when the data is needed.

Also read: How to Create a Simple Order Transaction Form with PHP

  • And it will look like the following image
  • Then add the code below right above to call and save the input form data using an Array, and also make the output data display
<center>
<table border="1" cellpadding="2" cellspacing="4">
  <?php
  $nama = $_POST['nama'];
  $tgl = $_POST['tgl'];
  $jk = $_POST['jk'];
  $hobi = $_POST['hobi'];

  foreach($nama as $key => $val){
  ?>
  
  <tr>
    <td align="center" colspan="2">
      <?php 
      echo '<b>Hasil Biodata yang di Inputkan</b><br>';?>   
    </td>
  </tr>
  <tr>
    <td><?php echo 'Nama'?></td>
    <td><?php echo $nama[$key];?></td>
  </tr>
  <tr>
    <td><?php echo 'Tempat Tanggal Lahir';?></td>
    <td><?php echo $tgl[$key];?></td>
  </tr>
  <tr>
    <td><?php echo 'Jenis Kelamin';?></td>
    <td><?php echo $jk;?></td>
  </tr>
  <tr>
    <td><?php echo 'Hobi';?></td>
    <td><?php echo $hobi[$key];?></td>
  </tr>
  <?php 
    }
   ?>
</table>
</center>
</html>
</div>

Note: Shown above $ name = $ _POST [‘name’]; You can use this command to call the post method that you created earlier then re-initialize it using PHP. Then the function of Foreach there is used for loops whose data is an Array, and later the loop will be called using echo $ nama [$ key] ;.

  • And here is what the output will look like when you input the data

Maybe that’s all my tutorial on How to Create Simple Input and Output Forms with PHP without a Database, hopefully it’s useful, and don’t forget to share this article with those who need it.

Leave a Reply

Your email address will not be published. Required fields are marked *