0

can i create multiple form look like the one in phpmyadmin where the user can create multiple forms by selecting a number from option dropdown list to insert multiple value

<form>

    <input type="text" />
    <input type="text" />
    <input type="text" />


</form>


<select>

    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>

</select>

this is the code i am using

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

    <select name="prog_lang">

    <?php   

    if($questions = $num_of_questions){
        $num_of_questions = 1;

        for ($i=1; $i<=$num_of_questions; $i = $i + 1){

            echo "<label>السؤال رقم #".$i."</label><br>";
            echo "<textarea name='"."q".$i."' rows='10' cols='50'></textarea><br>";
            echo "<label>الاجابات الممكنة:</label><br>";

            for($j=1; $j<=4; $j = $j + 1){

                echo '<input class="choice" type="text" name="'.'choice'.$i.$j.'" id="choice'.$i.$j.'"/>';
                echo '<input class="correct" type="radio" name="'.'correct'.$i.'" value="correct'.$i.$j.'"/>';
                echo '<label>صحيحة</label><br>';

            }

            echo "<br><br>";
        }
    }
    ?>

    </select>

    <input style="color:blue; font-size:14pt; width:100;"type="submit"  value="حفظ الاختبار" />

</form>
2
  • What php code do you have? Commented Jun 30, 2016 at 9:18
  • i have posted the code i am using @Minzkraut Commented Jun 30, 2016 at 9:40

1 Answer 1

1

I suggest to use JavaScript in order to manipulate the DOM. However you can do it with PHP as well:

First you need to know how many input:

<form action="" method="post">
 <select name="howManyInput">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
 </select>
</form>

In the 'action' page you get the value of 'howManyInput':

<?php 
 $howMany = $_POST['howManyInput'];
?>

Then you print the input you need in a 'for' loop:

<form action="" method="post">
<?php
 for( $i=0; $i<$howMany; $i++ ){
   echo '<input name="inputName'.$i.'" >';
   // if you need more the 1 input for '$howMany' echo it here
 }
?>
</form>

The first form take you to the page where the user can insert data. In that page you print as many input the user select in the previous page.

When the second form is submitted it goes to a page that receive all data.

Sign up to request clarification or add additional context in comments.

3 Comments

can you show me an example how to use javascript to do it ?
Here is a Fiddle by Jared Williams jsfiddle.net/tZPg4/16393 that show the process. the code is commented. Hope this can be helpful.
thank you i think it's more than helpfully @Antonio Milo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.