Saving value of check box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mattiace
Forum Newbie
Posts: 1
Joined: Mon Nov 17, 2008 10:08 pm

Saving value of check box

Post by mattiace »

Sorry if this is in the wrong section.

I am designing a survey spread out over multiple pages and have alot of yes/no questions using radio buttons.
I want to be able to offer users to go back and change questions and at the same time keep there answer checked.
I did get it to work with alot of "if statements" but the code is messy and I have to apply it to every question. Is there a way to check a radio button based on a variable?
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Saving value of check box

Post by it2051229 »

yes... try naming all the checkboxes with the same name and by the time you CATCH the values using PHP code that is automatically an ARRAY.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Saving value of check box

Post by aceconcepts »

However, when you rename all the checkbox elements, also add an opening and closing set of square brackets after its name e.g.:

Code: Select all

<input type="checkbox" name="check1[]" />
The square brackets tells PHP that this element is being passed as an array.
Post Reply