Jump to content

[SOLVED] Keep a check box checked


phpretard

Recommended Posts

I am validating a form with PHP and it contains check boxes, text, radios etc...

 

The short logic is:

-At least one check box has to be checked

-At least one radio has to be ticked

-And one text box has to be filled

 

If I check a box and tick a radio but do not fill in the text box it validates fine but the check box becomes "un-checked" afterwards.

 

So my question is what is the recommended way keep check boxes checked and radios ticked while validating the rest of the form?

 

I know the hard way to do it but I was hoping for some advise on it.

 

<input type="checkbox" name="referred[]" value="Internet" /> Internet
<input type="checkbox" name="referred[]" value="Radio" /> Radio
<input type="checkbox" name="referred[]" value="Television" /> Television
<input type="checkbox" name="referred[]" value="Billboard" /> Law Talk
<input type="checkbox" name="referred[]" value="" /> Billboard
<input type="checkbox" name="referred[]" value="Newspaper" /> Newspaper
<input type="checkbox" name="referred[]" value="Phone Book" /> Phone Book
<input type="checkbox" name="referred[]" value="Attorney Referral" /> Attorney Referral
<input type="checkbox" name="referred[]" value="Friend" /> Friend

 

 

Thanks.

Link to comment
Share on other sites

If you print the check boxes dynamically it will be easier. You could store the checked boxes in a hidden input field as well and use javascript upon body load. Validating on the client side might be an idea too if you don't really mind not maintaining the checked boxes for that very little clique that do not use javascript.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.