Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 21st Jul 2010, 10:16 AM   #1
Warrior Member
 
Join Date: 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Check Boxes in PHP
Share on: 
fb share twitter share gplus share more share

Can anyone tell me how to use check boxes in the following php files?

contact form - contact.php
template for mail - contact-mail-html.tpl.php
contact-process.php - validates form
stevenc777 is offline  
Unread 21st Jul 2010, 11:23 AM   #2
Warrior Member
 
Join Date: 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: Check Boxes in PHP
Share on: 
fb share twitter share gplus share more share

Since you have not provided the code for these files, i'll let u know the basic behind checkboxes in PHP

say ur html goes as <input type="checkbox" name="my_checkBox" value="myValue" />

then in PHP
<?=(isset($_PHP['my_checkBox']))?'checkbox was checked':'It was not checked'; ?>
heroic is offline  
Unread 21st Jul 2010, 06:03 PM   #3
Web Designer
 
Join Date: 2010
Location: Utah
Posts: 18
Thanks: 0
Thanked 1 Time in 1 Post
Default
Re: Check Boxes in PHP
Share on: 
fb share twitter share gplus share more share

It depends what you want to do? PHP doesn't actually output check boxes, that's done with HTML. PHP is for using the data it gets from that checkbox, either to change what the user sees, put the info in a database, or something like that.

A checkbox is as simple as

<input type="checkbox">

Though you'll probably want a name and a value as well to do anything useful with it.
luminousnerd is offline  
Unread 21st Jul 2010, 10:29 PM   #4
Active Warrior
 
Join Date: 2010
Location: India
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: Check Boxes in PHP
Share on: 
fb share twitter share gplus share more share

Hi,

Below I am mentioned the code for check boxes in php with form action. Please find it.

<?php
$box=$_POST['box'];

while (list ($key,$val) = @each ($box)) {
echo "$val,";
}

echo "<form method=post action=''>";
echo "<table border='0' cellspacing='0' style='border-collapse: collapse' width='100' >
<tr bgcolor='#ffffff'>
<td width='25%'><input type=checkbox name=box[] value='John'></td>
<td width='25%'>John</td>
<td width='25%'><input type=checkbox name=box[] value='Mike'></td>
<td width='25%'>Mike</td>
<td width='25%'><input type=checkbox name=box[] value='Rone'></td>
<td width='25%'>Rone</td>
</tr>
<tr><td colspan =6 align=center><input type=submit value=Select></form></td></tr>
</table>";
?>
godwinsam is offline  
Unread 24th Jul 2010, 11:41 PM   #5
Warrior Member
 
Join Date: 2010
Posts: 20
Thanks: 0
Thanked 1 Time in 1 Post
Default
Re: Check Boxes in PHP
Share on: 
fb share twitter share gplus share more share

you need to have the checkbox added in the main file (the form)

and then in PHP the only thing you really need to use is
the isset() command , since a checkbox in PHP will never be available in the $_POST array
unless it's checked.


If it's checked , it will appear as TRUE , or 1. so the only real thing left to do when working it out on the php side
is to check if it's SET with isset($_POST["mycheckbox"])
Itamar is offline  
Unread 24th Aug 2010, 11:35 PM   #6
Active Warrior
War Room Member
 
Join Date: 2007
Location: USA
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: Check Boxes in PHP
Share on: 
fb share twitter share gplus share more share

It won't equal TRUE or 1... It'll equal the value. i.e. John, Mike, Rone

isset is appropriate; just make sure you know what you're getting as the value. This is a checkbox array. It's not as straight-forward. You'll get an array called "box" if ANY of the checkboxes are set, and then you have to iterate (typically using "foreach") to find all the checkboxes checked.

PM me if there are further questions. I do cover this in my course at OnlinePHPClass.com, and if you are interested, click the WSO link in my signature.
WarriorForSuccess is offline  
Closed Thread


Bookmarks

Tags
boxes, check, php


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 05:53 PM.