Re: Dynamic input fields in Form
| From: | Kevin Stone | Date: | Fri, 07 Feb 2003 18:24:29 +0000 |
| Subject: | Re: Dynamic input fields in Form | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-134769@lists.php.net to get a copy of this message | ||
Based on your description it could litterally be coded one of a hundred
different ways. The way I would code a small problem like this is in a
monolithic logical construct such as the if/else statement below. This
allows you to be a little bit more careless how you construct the page.
Another conditional statement can be put above or below the form to capture
and perform whatever is needed on the $_POST["carmake"] array.
<form method="POST" value="test.php">
<?
if (isset($_POST['numcars']) && is_numeric($_POST['numcars']))
{
for ($i=1; $i<=$_POST['numcars']; $i++)
{
echo "Car # $i
<select name=\"carmake[]\">
<option selected value=''>-- Choose Car Make --</option>
<option>Chrysler</option>
<option>Chevy</option>
<option>Dodge</option>
<option>Ford</option>
</select><br>";
}
}
else
{
echo "How many cars? <input type=\"text\" name=\"numcars\"
value=\"\"><br>";
}
?>
<input type="submit" value="SUBMIT">
</form>
- Kevin
----- Original Message -----
From: "Frank Keessen" <fkeessen@planet.nl>
To: "Jon Haworth" <jhaworth@witanjardine.co.uk>; <php-general@lists.php.net>
Sent: Friday, February 07, 2003 10:54 AM
Subject: Re: [PHP] Dynamic input fields in Form
> Hi,
>
> Thanks for the answer; but there is nobody who can show me an example in
> code???
>
> Regards,
>
> Frank
> ----- Original Message -----
> From: "Jon Haworth" <jhaworth@witanjardine.co.uk>
> To: <fkeessen@planet.nl>; <php-general@lists.php.net>
> Sent: Friday, February 07, 2003 1:45 PM
> Subject: RE: [PHP] Dynamic input fields in Form
>
>
> > Hi Frank,
> >
> > > I have a form where the user selects for example; how many cars
> > > you have: 4. Then it most dynamicly create 4 input fields
> > [...]
> >
> > Using only PHP, you'll have to make this a two-step process where page 1
> > collects the number of cars and posts to page 2, which generates the
form
> > accordingly.
> >
> > If is has to be done on the same page, you'll need to call a Javascript
> > function every time the number of cars changes. That function will have
to
> > add or remove <input>s from the form depending on the number of cars
> > entered, and of course the whole page will break completely for anyone
> > without Javascript.
> >
> > I'd make it a two-step process myself, it's considerably more robust and
> > offers considerably less room for problems (what happens if I claim I
have
> > five cars, fill out their details, and then change it to three cars?
which
> > details do you get rid of?)
> >
> > Cheers
> > Jon
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>