PHP Forms

Soldato
Joined
24 Nov 2002
Posts
16,378
Location
38.744281°N 104.846806°W
I have a form page then a processing page as the form action. Simple! Use $_POST["blah"] to fetch say the contents of a text box..

However, I'm not sure how to get checkboxes (on/off) or radioboxes (1,2,3 etc...) to pass the state to the processing page....?

For example, say I have 10 checkboxes.... I want to be able to say, if 1 on then blah, if 2 on then dah, if 3 on then boo etc.... Similar story with the radioboxes (if 1 then ding, if 2 then dong) etc....

Did that make sense?
 
Code:
if ( !empty($_POST['checkbox_1']) )
    // checkbox_1 is checked.

if ( !empty($_POST['checkbox_2']) )
    // checkbox_2 is checked.

if ( !empty($_POST['checkbox_1']) && empty($_POST['checkbox_2']) )
    // checkbox_1 is checked and checkbox_2 is not checked.
 
Code:
<label for="yes">Yes</label> <input type="radio" name="foo" id="yes" value="yes" />
<label for="no">No</label> <input type="radio" name="foo" id="yes" value="no" />

Code:
if ( $_POST['foo'] == 'yes' )
    // yes was checked
else
    // no was checked
 
Back
Top Bottom