I use the following function for my check boxes in forms in PHP.

Putting your form element creation into functions or even classes makes life
so much easier when you have to validate / change code.

you'll be glad you did it

Cheers

Brendon



function fncwriteformcheckbox($strname, $strid, $strvalue, $varcheckedvalue)
{
/*
 fncWriteFormCheckbox
 Returns HTML for a <checkbox> element
 Accepts form element name as string
 Accepts form element ID as string
 Accepts form element value as string
 Accepts form element checked value as string or array.
 If checked value = default value then "checked" is written
 to the HTML stream

 Adapted from ASP functions by Ken Schaefer.
*/
define("PROC", "fncwriteformcheckbox");
$strtemp = "<input type=\"checkbox\" name=\"" . $strname . "\" ID=\"" .
$strid . "\" value=\"" . $strvalue . "\"";

if (is_Array($varcheckedvalue)) {
        foreach ($varcheckedvalue as $varcheckedvalueelement) {
           if ($varcheckedvalueelement == $strvalue) {
                        $strtemp .= " checked";
                        break;
           }
        }
} else {
        if ($varcheckedvalue == $strvalue) {
                $strtemp .= " checked";
        }
}
$strtemp .= ">\n";
return $strtemp;
}



----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 05, 2002 5:06 PM
Subject: [PHP] checkboxes and selection lists


Hi, as a beginner I find the way you declare variables through HTML-forms
quite straightforward. But the reverse, to put the same variables back into
a form field is not so obvious for selection lists and checkboxes.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to