Form Re-Population?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
virgil
Forum Commoner
Posts: 59
Joined: Thu Jun 13, 2002 11:43 pm
Location: New York, U.S.

Form Re-Population?

Post 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
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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.
virgil
Forum Commoner
Posts: 59
Joined: Thu Jun 13, 2002 11:43 pm
Location: New York, U.S.

Post 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 :)
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post 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.
virgil
Forum Commoner
Posts: 59
Joined: Thu Jun 13, 2002 11:43 pm
Location: New York, U.S.

Post 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
Post Reply