Need help collecting data from a form (loop) that changes

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Post by swirlee » Thu Jul 24, 2003 7:59 pm

Yes, you need to put these values into an array. To make PHP put the contents a bunch of HTML form fields into an array, you must give them all the same name, followed by []. Like so:

Code: Select all

<form action="script.php" method="POST">
   <?
      for($i = 0; $ < 3; $i++) {
         echo 'Input ' . $i . ":<br />\n";
         echo '<input type="text" name="myarray[]">', "<br />\n";
      }
   ?>
</form>


This should generate a form with three text fields with labels "Input 1", "Input 2", and "Input 3", and when the form is submitted, all of their data will be lumped into the array $_POST['myarray'].

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest