Swoole\Form::checkbox PHP Method

checkbox() static public method

多选按钮
static public checkbox ( string $name, array $option, string $default = null, boolean $self = false, array $attrArray = null, string $label_class = '' ) : string
$name string 此radio 的 name 标签
$option array 要制作radio 的数
$default string 如果要设定默认选择哪个数据 就在此填入默认的数据的值
$self boolean 设置为ture,option的值等于$value
$attrArray array html的属性 例如 class="x1"
$label_class string
return string
    static function checkbox($name, $option, $default = null, $self = false, $attrArray = null, $label_class = '')
    {
        $htmlStr = "";
        $attrStr = self::input_attr($attrArray);
        $default = array_flip(explode(self::$checkbox_value_split, $default));
        foreach ($option as $key => $value) {
            if ($self) {
                $key = $value;
            }
            if (isset($default[$key])) {
                $htmlStr .= "<label class='{$label_class}'><input type=\"checkbox\" name=\"{$name}[]\" id=\"{$name}_{$key}\" value=\"{$key}\" checked=\"checked\" {$attrStr} />" . $value . '</label>';
            } else {
                $htmlStr .= "<label class='{$label_class}'><input type=\"checkbox\" name=\"{$name}[]\" id=\"{$name}_{$key}\" value=\"{$key}\"  {$attrStr} />" . $value . '</label>';
            }
        }
        return $htmlStr;
    }

Usage Example

Example #1
0
 function profile()
 {
     if ($_POST) {
         if (empty($_POST['nickname'])) {
             return Swoole\JS::js_back('昵称不能为空!');
         }
         if (!empty($_FILES['avatar']['name'])) {
             global $php;
             $php->upload->thumb_width = 90;
             $php->upload->thumb_height = 120;
             $php->upload->thumb_qulitity = 90;
             $php->upload->base_dir = "/static/uploads/avatar";
             $upfile = $php->upload->save('avatar');
             if ($upfile === false) {
                 return Swoole\JS::js_back('上传失败!');
             }
             $set['avatar'] = $_SESSION['user']['avatar'] = $upfile['thumb'];
         }
         $set['nickname'] = trim($_POST['nickname']);
         $set['intro'] = trim($_POST['intro']);
         $set['company'] = $_POST['company'];
         $set['blog'] = $_POST['blog'];
         $set['mobile'] = $_POST['mobile'];
         $set['sex'] = (int) $_POST['sex'];
         $set['education'] = (int) $_POST['education'];
         $set['skill'] = implode(',', $_POST['skill']);
         $set['php_level'] = (int) $_POST['php_level'];
         $u = model('UserInfo');
         $u->set($this->uid, $set);
         $_SESSION['user']['realname'] = $set['realname'];
         $_SESSION['user']['mobile'] = $set['mobile'];
         return Swoole\JS::js_back('修改成功!');
     } else {
         require WEBPATH . '/dict/forms.php';
         $_u = model('UserInfo');
         $u = $_u->get($this->uid)->get();
         $_skill = model('UserSkill')->getMap(array());
         $_forms['sex'] = Swoole\Form::radio('sex', $forms['sex'], $u['sex']);
         $_forms['education'] = Swoole\Form::select('education', $forms['education'], $u['education']);
         $_forms['skill'] = Swoole\Form::checkbox('skill', $_skill, $u['skill']);
         $_forms['level'] = Swoole\Form::radio('php_level', $forms['level'], $u['php_level']);
         $this->swoole->tpl->assign('user', $u);
         $this->swoole->tpl->assign('forms', $_forms);
         $this->swoole->tpl->display();
         //$this->view->showTrace();
     }
 }
All Usage Examples Of Swoole\Form::checkbox