/    Sign up×
Community /Pin to ProfileBookmark

prefill form data from database – radio and checkboxes

I am trying to prefill a form with data from a database, this form has previously been saved by the user. I have been able to prefill the text fields using <?php echo $Q12: ?>, but when it comes to the radio buttons or checkboxes this doesn’t work. Also, in regards to a group of radio buttons all named Q5 for example, how do I preselect the correct choice of the group. Any information related to prefilling radio and chackboxes would be appreciated.

Thanks
Mike

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@MstrBobJul 27.2004 — Something like :
[code=php]
<form action="form.php" action="post">
<fieldset>
<legend>Question #5</legend>
<input type="radio" value="1" name="Q5" <?php if($q5==1){echo("checked="checked"");}?> />Yes<br />
<input type="radio" value="2" name="Q5" <?php if($q5==2){echo("checked="checked"");}?> />No<br />
<input type="radio" value="3" name="Q5" <?php if($q5==3){echo("checked="checked"");}?> />Maybe So<br />
</fieldset>
</form>
[/code]
Copy linkTweet thisAlerts:
@mcherneckiauthorJul 27.2004 — MstrBob - Thank you, works perfect.

Mike
×

Success!

Help @mchernecki spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...