216 users online (0 members and 216 guests)  

  Results 1 to 2 of 2


  1. Replies: 4
  2. Replies: 1
  3. Pass Form Checkbox Value on Click    Forum: Javascript Forum
    Replies: 1
  4. Replies: 3
  5. Replies: 5
  1. #1
    perlprogramming's Avatar
    New User

    Join Date
    Mar 2007

    Exclamation How to pass an array through a form?

    I am setting up a database utility where specific engineers are assigned to various projects. Projects will be added from time to time, so it can't be hard-coded. See the code below. It simply creates a list of project names, each with its own drop-down menu with a list of engineers, allowing the user to assign all of projects a unique responsible engineer.

    print "
    <form method=\"POST\" action=\"cgi/assignperson.pl\">";
    <INPUT TYPE=\"hidden\" NAME=\"total\" VALUE=\"$numberofprojects\">
    for ($x=0; $x < $numberofprojects; $x++) { 
    print "
    <p>$program[$x]: <select size=\"1\" name=\"assignedperson[]\">
    <option value=\"Person1\">Person1</option> 
    <option value=\"Person2\">Person2</option>
    <option value=\"Person3\">Person3</option>
    <option value=\"Person4\">Person4</option>
    <option value=\"Person5\">Person5</option>
    <option value=\"Person6\">Person6</option>
    } # end for loop to create form drop-downs
    print "
    <p><input type=\"submit\" value=\"Submit\" name=\"B1\"></p>
    I understand that you can grab the value of a single parameter using a statement like this:
    $total = $param{total};
    Am I sending the data correctly and how do I retrieve the array of data submitted in the form (like the assignedperson[] array shown above), after it has been submitted? Any ideas?
    Last edited by vinyl-junkie; 03-07-2007 at 10:23 PM. Reason: Added code tags

  2. #2
    pageBuzz.com's Avatar
    New User

    Join Date
    Oct 2006

    Re: How to pass an array through a form?

    $program[$x] is the x number in the array. So where x = 0, $program[$x] would be the first element of the array @program.

    Just rememebr to define the array first either from a list like

    open (DATAFILE, "$datafile");
    close DATAFILE;

    Now $program[0] is the first line of the file. $program[1] is the second and so on.

Tags for this Thread