Checkbox validation and save state

OK, lets say I have a checkbox for, say, agree to terms. BUT, I have a form that has required information that has to be validated against some conditions.

Now, my problems are [LIST]how to validate that the box is actually checked and display the appropriate message
[/LIST][LIST]how to preserve the checked state - if checked and other errors cause the form to refresh - so the user can fix the errors
[/LIST]

So, for the sake of argument, my code is something like:

<input type="checkbox" name="waiverAgree" value="<?= htmlentities($values['waiverAgree']) ?>" />		

How can I call my function VerifyForm(&$values, &$errors) where $values[‘waiverAgree’] needs to be processed. Or… am I trying something really different or far out??

Thanks
F

Hi ,

where you want to check status of your checkbox on clientside or on serverside. ?

Anyways just make one hidden input (textbox) and save value or status in there.
So latter on you can check what was the last status of the checkbox.

Cheers

tejash,

OK… now can you give me an example of that as I don’t quite understand what exactly you are aluding to.

Thanks
F

Hi fredep57,

As i understand you want to take some action on status of checkbox. I mean its selected or not selected . And if selected than what value was there. right?

If so than what you can do is, create one hidden textbox.
When someone checked checkbox than grab the value of checkbox and set it as a value of hidden textbox by javascript.

Now whenever you want to check want happened, you can retrieve value of textbox. If its empty than nothing was checked. If there is some value than on base of value you can decide what further action you want to perform.

Hmm not sure I want to use javascript - have had some real problems with them in the past.

Is there a PHP way of doing this? I think someone has done it in PHP only but can’t find anything on the web that relates to it.

Thanks and still looking for a good example, tutorial, etc. to SHOW me what and how to do this.

F