| | #1 |
| Warrior Member Join Date: 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
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 |
| |
| | #2 |
| Warrior Member Join Date: 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
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'; ?> |
| |
| | #3 |
| Web Designer Join Date: 2010 Location: Utah
Posts: 18
Thanks: 0
Thanked 1 Time in 1 Post
|
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. |
| |
| | #4 |
| Active Warrior Join Date: 2010 Location: India
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
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>"; ?> |
| |
| | #5 |
| Warrior Member Join Date: 2010
Posts: 20
Thanks: 0
Thanked 1 Time in 1 Post
|
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"]) |
| |
| | #6 |
| Active Warrior War Room Member Join Date: 2007 Location: USA
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
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. |
| |
|
| Bookmarks |
| Tags |
| boxes, check, php |
| |