LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   checkboxes in php [on/off] (http://www.linuxquestions.org/questions/programming-9/checkboxes-in-php-%5Bon-off%5D-381397/)

ALInux 11-09-2005 06:20 AM

checkboxes in php [on/off]
 
Hi
I want to add a checkbox to my form that should act as a on off regulator..........I googled but the only results I found were related to multiple checkboxes.........can anybody tell me how to check if a single checkbox is checked ?

fouldsy 11-09-2005 06:40 AM

Something like this would be in your form:
Code:

<input type='checkbox' name='a1'<?php if( $row["a1"] == '1') { echo "CHECKED"; } ?>>Block / Unblock Website
which is then read in by your processing script as such:
Code:

$a1 = $HTTP_POST_VARS["a1"];
In that case, my script is querying a MySQL database, working out whether an option should be ticked, and then ticking or unticking the check box. Has about 30 options dynamically handled, with the procesing script updating the choices the user makes. You can call it something other than 'a1' and then simply read in your named variable whilst processing. If it's unchecked, the result is 'off', if ticked, the result is 'on'. A quick check to process different commands based on it's value would be:
Code:

if ($a1 === 'on') {
                $a1 = 1;
        }

Hope it helps, otherwise let us know what you're trying to do.


All times are GMT -5. The time now is 09:43 AM.