Create Dynamic input text fields in html using PHP

      Sometimes we need to create input fields in the form according to the need of users. Let it be dynamic,If you don't know the no.of fields required exactly. In this tutorial we see how to generate a dynamic input field  & how to print those values in a for loop using php.
Grab latest version

Get the Number of text fields to generate & pass it to main.php

   <form action="main.php" method="post">
        No.of Text fields <input type="text" name="nos" />
       <input type="submit" value="Submit" />

  • $nos going to be no.of times the for loop iterate.


<form action="result.php" method="post">


       Variables:<input size="7" type="text" name="c<?=$i?>" class="input" value="" required="required"/>


      <input type="hidden" name="nos" value="<?=$nos?>" />
      <input type="submit" value="Submit" />

      These values are submitted to result.php. Let us see how to print the values in result.php page continue reading .

Make a comment it will be helpful to improve the post.


Post a Comment

Don't Forget To Join US Our Community