Click to See Complete Forum and Search --> : [RESOLVED] Checkbox form field to be sticky


focus310
05-12-2007, 05:31 AM
Hello:

I'm trying to make a form field which is a checkbox be sticky.

For starters, did I correctly code the checkbox for it to be sticky?

When I run the script, I'm receiving this message:
Parse error: syntax error, unexpected ';'
and I can't seem to find the problem.

This is the line of code causing the problem:

<input type="checkbox" name="availability[]" id="availability" value="Weekday Mornings"<?php echo (isset ($_SESSION['availability']) && $_SESSION['availability'] == 'Weekday Mornings' ? ' checked="checked"' : ''; ?> />Weekday mornings<br>


I do have the variable validated in the beginning of the script. Everything works fine but when I started to make the fields sticky, the checkbox field doesn't want to remain checked.

This is my validation code:

if (isset($_POST['availability']) && (is_array($_POST['availability']))) {
$_SESSION['availability'] = TRUE;
} else {
$errors[] = 'Availability is a required field, Please select at least one.';
}


Thanks for all the help.

Suhas Dhoke
05-12-2007, 07:25 AM
Hello Focus.

The problem is, you not complete the closing bracket after the 'Weekday Mornings'.
I modified your code... check it.


<input type="checkbox" name="availability[]" id="availability" value="Weekday Mornings"<?php echo (isset($_SESSION['availability']) && $_SESSION['availability'] == 'Weekday Mornings') ? ' checked="checked"' : ''; ?> />Weekday mornings<br>

focus310
05-12-2007, 08:09 AM
Hello:

Thank you for the reply. I updated my script with the change in code and what is happening is the following. When a person checks two boxes and clicks submit, all of the checkboxes show checkmarks.

After submit, only the boxes the user checked should only remain checked. It seems like I need to write some sort of logic to check to see what is checked or not and then check the boxes which are true. I think. Not sure how to do it.

This is the code now:

<input type="checkbox" name="availability[]" id="availability" value="Weekday mornings"<?php echo (isset($_SESSION['availability']) && $_SESSION['availability'] == 'Weekday mornings') ? ' checked="checked"' : ''; ?> />Weekday mornings<br>
<input type="checkbox" name="availability[]" id="availability" value="Weekday afternoons"<?php echo (isset($_SESSION['availability']) && $_SESSION['availability'] == 'Weekday afternoons') ? ' checked="checked"' : ''; ?> />Weekday afternoons<br>
<input type="checkbox" name="availability[]" id="availability" value="Weekday evenings"<?php echo (isset($_SESSION['availability']) && $_SESSION['availability'] == 'Weekday evenings') ? ' checked="checked"' : ''; ?> />Weekday evenings<br>
<input type="checkbox" name="availability[]" id="availability" value="Weekday evenings"<?php echo (isset($_SESSION['availability']) && $_SESSION['availability'] == 'Weekday evenings') ? ' checked="checked"' : ''; ?> />Weekday evenings<br>