Page 1 of 1

Form Re-Population?

Posted: Tue Jul 02, 2002 10:43 pm
by virgil
Hi PhP's (Peeps) :)

I'm looking for an old post that I saw, and now cant seem to find, concerning how to reset complicated form values from a record in a database (MySQL) so that the info can be updated. i.e. How do you restore the submitters original choices on a form? <value=<?$fieldname?>/> ? How can you re-select items in a dropdown menu? Thanks for any advice, code examples or tutorials locations. Virgil

Posted: Wed Jul 03, 2002 3:27 am
by Wayne
On the SELECT OPTION that you want to be selected enter

Code: Select all

<OPTION VALUE="this" SELECTED>This text</OPTION>
in the OPTION tag.

Compare the select values against that submitted and when you have a match enter the above code.

Posted: Wed Jul 03, 2002 7:28 am
by virgil
Can anyone be a little more elaborate on how to get the php code to insert into the html? Just a larger code snippet would really be helpful. Thanks again. Virgil :)

Posted: Wed Jul 03, 2002 9:02 am
by RandomEngy
Basically, you want to insert the database value where the default value of the form is.

Code: Select all

<input type="text" name="mytext" value="<?=$phpvariable?>">
...
<option value="An option"<? if($myvar == 5) echo(" selected"); ?>>
...
<textarea name="frank"><?=$anotherphpvariable?></textarea>
...
<input type="radio" name="myradiogroup" value="34"<? if($phpvar == 12) echo(" checked"); ?>>
Just load the data you want from the database and put it in a variable, and use it in those places.

Posted: Wed Jul 03, 2002 5:54 pm
by virgil
I see, said the blind man. Thought it would be harder than that.


THAT'S EASY!!!(I said as I attempted to cross the Bridge of Death).

Thanks alot for the help! Virgil :D