Page 1 of 1

forms

Posted: Sat Aug 10, 2002 5:02 pm
by lexx
What are the key words/variables for radio and check boxes?

if checkbox== checked?

Thats for anyhelp

Posted: Sat Aug 10, 2002 7:03 pm
by volka
it depends ;)
try this one

Code: Select all

<html><body>
<form method="POST">
	<fieldset><legend>single checkboxes</legend>
		<input type="checkbox" name="single" />a single checkbox<br/>
		<input type="checkbox" name="cbwithvalue" value="myValue"/>a single checkbox with value<br/>
	</fieldset>
	<fieldset><legend>checkboxe-array without value</legend>
		<input type="checkbox" name="cbarray&#1111;]"/>checkbox 'array' #1<br/>
		<input type="checkbox" name="cbarray&#1111;]"/>checkbox 'array' #2<br/>
		<input type="checkbox" name="cbarray&#1111;]"/>checkbox 'array' #3<br/>
	</fieldset>
	<fieldset><legend>checkboxe-array with value-properties</legend>
		<input type="checkbox" name="cbarrayV&#1111;]" value="A"/>checkbox 'array' with value #1<br/>
		<input type="checkbox" name="cbarrayV&#1111;]" value="B"/>checkbox 'array' with value #2<br/>
		<input type="checkbox" name="cbarrayV&#1111;]" value="C"/>checkbox 'array' with value #3<br/>
	</fieldset>
	<input type="submit"/>
</form>
<pre>
<?php
	print_r($_POST);
?> 
</pre>
</body>
</html>
<input type="checkbox" name="single" /> -> $_POST['single'] == 'on' or not set

<input type="checkbox" name="cbwithvalue" value="myValue"/> -> $_POST['cbwithvalue'] == 'myValue' or not set

<input type="checkbox" name="cbarray[]"/> -> $_POST['cbarray'] is an array with numerical indicies for all checked checkboxes -> 'on' (no position information is stored; always beginning at 0)

<input type="checkbox" name="cbarrayV[]" value="A"/> -> $_POST['cbarrayV'] is an array with numerical indicies for all checked checkboxes holding each value of the corresponding input-element

just remeber that if your're using name="cbarray[]" without value property you will loose the information which checkboxes have been checked

Posted: Sun Aug 11, 2002 12:05 am
by lexx
I have <input type="checkbox" name="siteOFF">
how do I check if the checkbox is ckecked?

Posted: Sun Aug 11, 2002 5:18 pm
by lexx
anyone? :roll:

Posted: Sun Aug 11, 2002 5:46 pm
by w3cynic
Volka answered you!!

Code: Select all

if ($_POST&#1111;'siteOFF'])
&#123;
// your checkbox is set!
&#125;
Or if you are using GET method then use the $_GET array instead.

Posted: Mon Aug 12, 2002 12:35 pm
by lexx
Oh! lol, sorry I didnt get his thing. Thanks alot :lol:

Posted: Mon Aug 12, 2002 12:43 pm
by volka
doesn't matter. Sometimes I don't get my own points ;)