php checkbox question

Started on the old forum in December 2012 · view the original in the archive · old links redirect here

3 replies · 1,122 views · started 13 years ago · 1 min read

3 participants
katmac Newbie · 2 posts #1

Hi

I have a form with a list of checkboxes (http://mandatorymarketinginc.com/web/sample-01.png)

These checkbox values were previously saved to a table called "comp-profile-03-specialties" and I got code working on the html form to to check and if specialty selected the checkbox is checked.

On the html form checkboxes name is "specialties[]".

However my problem comes in when I want to update the checkboxes to account for the possibilities if the a checkbox is de-selected or another checkbox is added.

How would I go about doing this?

Thanks.

kevk3v Senior · 332 posts #2

If the checkbox is checked, the value of it will be passed. Otherwise it won't.

<?php
if (isset($_POST['mycheckbox']))
{
    echo "checked!";
}
else
{
echo "Not checked";
}
?>

Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

arnage Lead · 811 posts #3

katmac wrote: Hi

I have a form with a list of checkboxes (http://mandatorymarketinginc.com/web/sample-01.png)

These checkbox values were previously saved to a table called "comp-profile-03-specialties" and I got code working on the html form to to check and if specialty selected the checkbox is checked.

On the html form checkboxes name is "specialties[]".

However my problem comes in when I want to update the checkboxes to account for the possibilities if the a checkbox is de-selected or another checkbox is added.

How would I go about doing this?

Thanks.

It would be sooo much easier to help if you would post the code.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
arnage Lead · 811 posts #4

Since i don't know where you are with your code, i can only suggest you that before the form you collect relevant values with mysql query and check it while parsing the form:

echo '<option value="'.$var.'"'.($checked['value'] == $var ? ' selected="selected">' : '>').$name.'</option>'."\n";

This way saved and changed values are compared and changed or not with next submit...

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close