forms

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
lexx
Forum Newbie
Posts: 21
Joined: Sat Jun 08, 2002 10:30 pm

forms

Post by lexx »

What are the key words/variables for radio and check boxes?

if checkbox== checked?

Thats for anyhelp
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
lexx
Forum Newbie
Posts: 21
Joined: Sat Jun 08, 2002 10:30 pm

Post by lexx »

I have <input type="checkbox" name="siteOFF">
how do I check if the checkbox is ckecked?
lexx
Forum Newbie
Posts: 21
Joined: Sat Jun 08, 2002 10:30 pm

Post by lexx »

anyone? :roll:
w3cynic
Forum Newbie
Posts: 12
Joined: Sun Aug 11, 2002 11:06 am

Post 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.
lexx
Forum Newbie
Posts: 21
Joined: Sat Jun 08, 2002 10:30 pm

Post by lexx »

Oh! lol, sorry I didnt get his thing. Thanks alot :lol:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

doesn't matter. Sometimes I don't get my own points ;)
Post Reply