/    Sign up×
Community /Pin to ProfileBookmark

keeping checkboxes checked in form

I have this form:
[url]http://www.mikeglaz.com/606club/join.php#personality[/url]

When the user submits the form and there are some errors on the form (i.e. the form doesn’t submit but prints errors to the user, like blank fields) I want the form to remember all the fields. I’ve been using the $_POST variable to remember the state of the filled in fields. But I don’t know how to do an array of checkboxes. Right now I have 22 checkboxes and and I’m checking each $_POST[‘abc’][index]. But there can be a variable number of indices from 0 to 21. Does anyone know of a solution?

here’s my code:

[CODE]
<a name=”personality”><p class=”minusMargin”><b>Describe your personality:</b></a>
<table cellspacing=”5″ border=”0″ class=”personality”>
<tr>
<td><input type=”checkbox” name=”personality[]” value=”considerate” <?php if($_POST[‘personality’][0] == ‘considerate’) {echo ‘checked=”checked”‘;}?> />&nbsp;Considerate</td>
<td><input type=”checkbox” name=”personality[]” value=”confident” <?php if($_POST[‘personality’][1] == ‘confident’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Confident</td>
</tr>
<tr>
<td><input type=”checkbox” name=”personality[]” value=”open-minded” <?php if($_POST[‘personality’][2] == ‘open-minded’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Open-Minded</td>
<td><input type=”checkbox” name=”personality[]” value=”sociable” <?php if($_POST[‘personality’][3] == ‘sociable’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Sociable</td>
</tr>
<tr>
<td><input type=”checkbox” name=”personality[]” value=”fun” <?php if($_POST[‘personality’][4] == ‘fun’) {echo ‘checked=”checked”‘;}?>/>&nbsp;FUN</td>
<td><input type=”checkbox” name=”personality[]” value=”affectionate” <?php if($_POST[‘personality’][5] == ‘affectionate’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Affectionate</td>
</tr>
<tr>
<td><input type=”checkbox” name=”personality[]” value=”kind” <?php if($_POST[‘personality’][6] == ‘kind’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Kind</td>
<td><input type=”checkbox” name=”personality[]” value=”ambitious” <?php if($_POST[‘personality’][7] == ‘ambitious’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Ambitious</td>
</tr>
<tr>
<td><input type=”checkbox” name=”personality[]” value=”quiet” <?php if($_POST[‘personality’][8] == ‘quiet’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Quiet</td>
<td><input type=”checkbox” name=”personality[]” value=”adventurous” <?php if($_POST[‘personality’][9] == ‘adventurous’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Adventurous</td>
</tr>
<tr>
<td><input type=”checkbox” name=”personality[]” value=”reliable” <?php if($_POST[‘personality’][10] == ‘reliable’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Reliable</td>
<td><input type=”checkbox” name=”personality[]” value=”shy” <?php if($_POST[‘personality’][11] == ‘shy’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Shy</td>
</tr>
<tr>
<td><input type=”checkbox” name=”personality[]” value=”witty” <?php if($_POST[‘personality’][12] == ‘witty’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Witty</td>
<td><input type=”checkbox” name=”personality[]” value=”crazy” <?php if($_POST[‘personality’][13] == ‘crazy’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Crazy</td>
</tr>
<tr>
<td><input type=”checkbox” name=”personality[]” value=”silly” <?php if($_POST[‘personality’][14] == ‘silly’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Silly</td>
<td><input type=”checkbox” name=”personality[]” value=”humorous” <?php if($_POST[‘personality’][15] == ‘humorous’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Humorous</td>
</tr>
<tr>
<td><input type=”checkbox” name=”personality[]” value=”prankster” <?php if($_POST[‘personality’][16] == ‘prankster’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Prankster</td>
<td><input type=”checkbox” name=”personality[]” value=”well-read” <?php if($_POST[‘personality’][17] == ‘well-read’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Well-Read</td>
</tr>
<tr>
<td><input type=”checkbox” name=”personality[]” value=”well-traveled” <?php if($_POST[‘personality’][18] == ‘well-traveled’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Well-Traveled</td>
<td><input type=”checkbox” name=”personality[]” value=”not_traveled_enough” <?php if($_POST[‘personality’][19] == ‘not_traveled_enough’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Not Traveled Enough</td>
</tr>
<tr>
<td><input type=”checkbox” name=”personality[]” value=”articulate” <?php if($_POST[‘personality’][20] == ‘articulate’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Articulate</td>
<td><input type=”checkbox” name=”personality[]” value=”bussiness-like” <?php if($_POST[‘personality’][21] == ‘bussiness-like’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Business-Like</td>
</tr>
<td><input type=”checkbox” name=”personality[]” value=”foot_loose” <?php if($_POST[‘personality’][22] == ‘foot_loose’) {echo ‘checked=”checked”‘;}?>/>&nbsp;Foot Loose and Fancy Free</td>
<td>&nbsp;</td>
</tr>
</table>
</p>
[/CODE]

thanx,
mike

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@DorkySep 27.2011 — without seeing the php that you are processing with, it is impossible to say.
Copy linkTweet thisAlerts:
@mikeglazauthorSep 27.2011 — The PHP I posted is the only processing I have.
×

Success!

Help @mikeglaz 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...