Take all of the fields associated with one database record and
give them all the same suffix. You can use a counter to generate
suffixes. Add an additional hidden field to hold the number of
records on the form. For example (using the data you provided):
<input type="hidden" name="userid_1" value="1">
<input type="text" name="firstname_1" value="Pedro"> -
<input type="text" name="lastname_1" value="Montoya"> -
<input type="text" name="email_1" value="pedro@motoya.net"> -
<input type="text" name="department_1" value="dept 7"> -
Admin <input type="checkbox" name="admin_1">
<br>
<input type="hidden" name="userid_2" value="2">
<input type="text" name="firstname_2" value="Lisa"> -
<input type="text" name="lastname_2" value="Brannigan"> -
<input type="text" name="email_2" value="lisa@hotmail.com"> -
<input type="text" name="department_2" value="dept 6"> -
Admin <input type="checkbox" name="admin_2" checked>
<input type="hidden" name="count" value="2">
Process the returned data with something like this.
my $q = new CGI;
my $cnt = $q->param("count"); # validate for numeric and value in rang
+e
for my $sfx (1..$cnt) {
my $userid = $q->param("userid_$sfx");
my $first = $q->param("firstname_$sfx");
my $last = $q->param("lastname_$sfx");
my $email = $q->param("email_$sfx");
my $dept = $q->param("department_$sfx");
my $admin = $q->param("admin_$sfx");
# validate all values above and update user record
}
Since you're presenting many records to the user at one time, you
will probably have to update all of your database records since there
won't be any way to determine which were modified. You may be able to
detect modifications with some javascript. If so, I would add a
second hidden field for each record whose value could be changed by the javascript to
indicate that the record needs an update.
---
print map { my ($m)=1<<hex($_)&11?' ':'';
$m.=substr('AHJPacehklnorstu',hex($_),1) }
split //,'2fde0abe76c36c914586c';
|