I'm building a script in PHP that has 3 parts, spanning 3 pages. The first 2 were easy. But I'm kinda baffled at the third.
The script builds a form, according to how many elements the user specifies. Then, it displays the results on a webpage. If this sounds German to you, just read on.
The first page is a simple drop-down box, asking how many elements the form requires. Let's say a user chooses 5. After pressing submit, the user goes to page 2.
On this page, the actual form displays, showing text boxes. We're assuming the user chose 5 so this page has 5 boxes. I should note that I passed the variable on to the 3rd page as well, the one specifying the number 5, in this example.I used a for() to add the form elements. I was able to append the names I gave each element; see below:
($number is the var for the drop-down box at the very beginning)
<?php
for ($i=1; $i<=$number; $i++)
{
echo "Name For Member " . $i .":ย <INPUT TYPE=text NAME=name".$i . " SIZE=30><br>";
} ?>
Once the form is complete, the user presses submit and goes to the final page, the one that displays the user's input. THIS is the tricky part...
...how would I do this?
I passed the initial var from the first part to the second & then to the third. But now I'll need to be able to add:
$name = $_POST["name"];
But 'name' is affixed with a number ie With 5 in mind, all 5 text boxes are named name1, name2, name3 etc. I don't think I could use ["name" + 1] in this situation...
I think I'd need an array but I dunno how I'd set this up.
How do I do this? :p
The script builds a form, according to how many elements the user specifies. Then, it displays the results on a webpage. If this sounds German to you, just read on.
The first page is a simple drop-down box, asking how many elements the form requires. Let's say a user chooses 5. After pressing submit, the user goes to page 2.
On this page, the actual form displays, showing text boxes. We're assuming the user chose 5 so this page has 5 boxes. I should note that I passed the variable on to the 3rd page as well, the one specifying the number 5, in this example.I used a for() to add the form elements. I was able to append the names I gave each element; see below:
($number is the var for the drop-down box at the very beginning)
<?php
for ($i=1; $i<=$number; $i++)
{
echo "Name For Member " . $i .":ย <INPUT TYPE=text NAME=name".$i . " SIZE=30><br>";
} ?>
Once the form is complete, the user presses submit and goes to the final page, the one that displays the user's input. THIS is the tricky part...
...how would I do this?
I passed the initial var from the first part to the second & then to the third. But now I'll need to be able to add:
$name = $_POST["name"];
But 'name' is affixed with a number ie With 5 in mind, all 5 text boxes are named name1, name2, name3 etc. I don't think I could use ["name" + 1] in this situation...
I think I'd need an array but I dunno how I'd set this up.
How do I do this? :p
Last edited:








