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

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

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

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";

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