At the top of my head, I'd create some sort of Employee object, and keep an
array of Employees registered as a session variable across pages. Each time
your users click "add", they'd add the current employee information that
they just filled out to that array, and get the form again.
When they're finally done, the information they're submitting will also get
added to the array, and then the contents of that array would be listed out.
Next to each one will be a "delete this item" checkbox or button.
If you go the button route, just submit a hidden value or whatever which is
the numerical index into the array of Employees which to remove.
Haven't written any code, this is just conceptual at this point...
-----Original Message-----
From: Pam Will [mailto:pwill@m...]
Sent: Wednesday, August 29, 2001 2:51 PM
To: professional php
Subject: [pro_php] Array for Gathering Form Data?
I have a form page that is part of a much larger for that I want to have
repeat so they can enter as many or as little number of Employees as they
want.
It is asking for:
Employee Name
Date of Birth
Sex
More stuff, etc...
Then, at the button I want buttons for
Add Additional Employee
Done Entering Employees
The Done would act as a submit button-no issue here -- except I do want to
list all the information they added and then choose if they want to delete
one that they entered, modify one they entered, OR add more.
However, what do I attach behind the Add button? I don't want anything
written to the database until they choose Done and I don't want to have to
create 100's of pages to anticipate how many employees they might add...
(the existing form has a place for entering 20 employees is a table like
this:
Name DOB Sex More
Field 1 Field 2 Field 3 Field 4
Field 5 Field 6 Field 7 Field 8
etc...
So, how do I redisplay the same screen and yet keep capturing the data they
are entering in variables? At the end each Employee they add would be a
record in the database.
Here is some samples of the code I have right now:
<FORM NAME="Census" METHOD="post" ACTION="partners_page5.php">
<table width`0 border=0 cellpadding=0 cellspacing=0>
<tr><td>Employee Name<td><td><INPUT TYPE="text" NAME="Emp_Name" SIZEE
MAXLENGTHE></td></tr>
<tr><td>Date of Birth<td><td><INPUT TYPE="date" NAME="Emp_DOB"</td></tr>
<tr><td>Sex<td><td><select name="Emp_Sex">
<option value="-1">Please Select One...</option>
<option value="Female">Female</option>
<option value="Male">Male</option>
</select></td></tr>
</table>
<INPUT TYPE="SUBMIT" name="submit" VALUE="Done Entering Employees">
<!-- This code below captures the values from pages past and moves them
along the food chain using PHP -->
<?
if ($HTTP_POST_VARS) {
while (list($lvar, $lvalue) = each($HTTP_POST_VARS)) {
echo "<INPUT TYPE=HIDDEN NAME='$lvar' VALUE='$lvalue'>\n";
}
}
?>
All help is greatly appreciated! I think this might be something of a
shopping cart mentality???