Reputation: 26
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>
Upvotes: 0
Views: 570
Reputation: 81
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.
Upvotes: 1