Click to See Complete Forum and Search --> : automatically fill out forms in php


optech
03-23-2002, 01:02 PM
i've created an html form that allows a user to input data (duh)... all of the forms values are already in a MySQL database, and i've linked a combo drop-down box to the "name' value... what i want to do here is to have the rest of the form fill out with the pertaining data when the user selects a name from the existing list of names. dig?

the code i have so far is the easy part, and it fills up the combo box with a list from the DB, and will enter it back in when submitted, but the rest of the form stays blank (as i haven't coded that part in).


while ($contact = mysql_fetch_array($result1, MYSQL_ASSOC))
{
foreach ($contact as $col_value)
{
print "<option value=$col_value>$col_value</option>\n";
}
}



so what i want after this:
when the user selects name "dave" from the database, i want all the rest of the information from the "dave" row to fill in the remaining fields...

any ideas?

Bradmont5
03-23-2002, 03:20 PM
2 possible ways I can see -- have the form submit when a name is chosen then spew out another form with all the appropriate values, or use javascript to fill in the rest of the fields (which would probably be a worse option, since you'd have to send the entire contents of the table to the user whenever they went to the page.

Stuka
03-25-2002, 12:23 PM
I think Bradmont's got the right idea - only have the name choice available first, then, after the user selects the name, have the form come up with all the relevant values. Since PHP relies on the server for processing, you'll have to use this two-phase method. I used a MySQL db in a related fashion - users choose relevant info about their system, and are guided to an appropriate product - and it had to be a multi-step thing.

optech
03-25-2002, 09:49 PM
well, that's more or less my question:
how do i go about filling in a form when a user selects a certain item in a drop down menu?

:D

Stuka
03-26-2002, 02:37 PM
What I did was to separate the form into multiple pages, sort of "wizard" style. You could do the same with a single page however. Make the form self-referential:&lt;form action="this_script.php"&gt; Now when it's first entered, there will be no variables (such as $name) defined - so you just fill in the drop down box as you're doing. When the user selects the name and hits 'Submit', the same script is called again, but this time there will be a variable attached to the URL like so: <A HREF="http://mydomain.com/this_script.php?name="foo"" TARGET=_blank>http://mydomain.com/this_script.php?name="foo"</A> This time, your variable check (if ($name)) returns true, so you use the name to do your DB lookup, and fill in the form appropriately. Like I said, I set up something similar for our configurator page (http://www.spectrum-wallboards.com/cfgpg1.php) If you're interested, I can dig out some of the relevant code for you.