Exemplo n.º 1
0
 static function checkbox($name, $value = 1, $checked = false, $js = null)
 {
     if (is_array($value)) {
         $js = $value;
         $value = 1;
     } else {
         if (is_array($checked)) {
             $js = $checked;
             $checked = false;
         }
     }
     $js = $js ? $js : array();
     if (!defval($js, "id")) {
         $js["id"] = "htctl" . ++self::$_controlid;
     }
     self::$_lastcontrolid = $js["id"];
     if (!isset($js["class"])) {
         $js["class"] = "cb";
     }
     $t = '<input type="checkbox"';
     /* NB see Ht::radio */
     if ($name) {
         $t .= " name=\"{$name}\" value=\"" . htmlspecialchars($value) . "\"";
     }
     if ($checked === null) {
         $checked = isset($_REQUEST[$name]) && $_REQUEST[$name] === $value;
     }
     if ($checked) {
         $t .= " checked=\"checked\"";
     }
     return $t . self::extra($js) . " />";
 }