Re: Newbie help: Need code snippet ASAP
| From: | Matt McClanahan | Date: | Fri, 02 Jun 2000 17:27:30 +0000 |
| Subject: | Re: Newbie help: Need code snippet ASAP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-914@lists.php.net to get a copy of this message | ||
On Fri, 2 Jun 2000, Dion Vansevenant wrote:
> I apologize if this has been asked before, but I am new to PHP and have a
> rather short deadline for a page that needs to be built, so I hope someone
> will be able to help me.
>
> I am working on a form that a user here has to fill out containing variables
> lines of information. This form, when submitted will be emailed to a client
> with a return address for someone else in our company. Don't worry, it's
> perfectly legit and not spam.
<snip>
> What I need to do is enable the person filling the form to add as many of
> Lines 1 to 3 as they need, while still retaining any information already
> entered. So the form could look like this:
This sort of dynamic content isn't easy to do with web pages. One option
I might suggest would be to provide a box where the user can enter how
many groups of Lines 1 to 3 they plan on entering. That way, your form
can generate the desired number of lines. It's not a very elegant
solution from a UI standpoint, of course. I don't know if there's a
better way with DHTML or somesuch, but it'd surprise me. :)
Anyway, the code for that suggestion would simply be a for loop that spits
out the number of for fields desired. $fieldCount reflects how many
groupings of Lines 1 to 3 they want.
for( $i = 0; $i < $fieldCount; $i++ )
{ ?>
Line1: <input type="text" name="line1[]"><br>
Line2: <input type="text" name="line2[]"><br>
Line3: <input type="text" name="line3[]"><br>
<? }
Which will make three arrays of fields. So your first grouping would be
$line1[0], $line2[0], $line3[0], the second $line1[1], $line2[1],
$line3[1], and so on.
HTH,
Matt