Re: dynamic form help
| From: | Jason Lavigne | Date: | Thu, 23 Nov 2000 09:01:40 +0000 |
| Subject: | Re: dynamic form help | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-26709@lists.php.net to get a copy of this message | ||
I would create an array of the options then loop through them and checking
if the current option is the same as the current selection. Let's take your
example.
$array_options[] = 1;
$array_options[] = 2;
$array_options[] = 3;
echo "<SELECT>\n";
for ($j = 0; $j < count($array_options); $j++) {
echo "\t<OPTION";
if ($current_val == $array_options[$j]) {
echo " selected";
}
echo ">" . $array_options[$j] . "</OPTION>\n";
}
echo "</SELECT>\n";
This means that adding another option is easy and if $current_val is set
then it will always select the correct option. This can be expanded for
multiple selects as well.
Jay
----- Original Message -----
From: "Jon Rosenberg" <php@columbusinteractive.com>
To: "PHP List" <php-general@lists.php.net>
Sent: Wednesday, November 22, 2000 3:51 PM
Subject: Re: [PHP] dynamic form help
> Thanks for that bit of help...but, is there any way to do it where I don't
> have the list of options stored in the db? I can add them to the db, but
> I'd rather not since I have so many form fields to do. Thanks!!!
>
>
> ----- Original Message -----
> From: "Cristian Donoso" <cdonoso@woc.cl>
> To: "Jon Rosenberg" <php@columbusinteractive.com>; "PHP List"
> < >
> Sent: Wednesday, November 22, 2000 3:27 AM
> Subject: RE: [PHP] dynamic form help
>
>
> > > What would be the best way to do the following? I have a mysql db
> record,
> > I
> > > have it so people can login against the db and now I want to allow
them
> to
> > > edit the information about them in the db. The form they create their
> > entry
> > > with is a combination of text boxes and drop-down selection menus.
When
> > > they log in I want the form that comes up to have the values in it
that
> > they
> > > originally signed up with. I know how to populate the text box fields
> > > dynamicly with value=$var_name , but how can I make it so that the
> > selection
> > > drop-down menus have what they selected? I essentially need to be
able
> to
> > > write those parts of the form like this:
> > >
> > > drop-down:
> > >
> > > You have 3 choices, your current selection is...you can change it if
> you'd
> > > like and save it to the db:
> > > <SELECT>
> > > <OPTION>1</OPTION>
> > > <OPTION selected>2</OPTION>
> > > <OPTION>3</OPTION>
> > > </SELECT>
> > >
> > > how can I make it so that the 'selected' appears in the right place?
> and
> > > yet still include all the other options so they can change it if they
> want
> > > to?
> >
> > If you have stored in your DB the option, you can do something like
this:
> >
> > print "<SELECT>";
> > for ($i=1 ; $i<=3; $i++) {
> > ($i == $value_from_database) ? $sel = "selected" : $sel = "";
> > print "<OPTION $sel>$i</OPTION>";
> > }
> > print "</SELECT>";
> >
> > this only works if the $value_from_database is an INTEGER but that's the
> > idea.
> >
> > ______________________________
> > Cristian Donoso Monteiro
> > Temuco - Chile
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>