ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 表单字段 > 图片演示: ![](https://img.kancloud.cn/a4/af/a4afb5abfa25dae02ea4f0b673b0dbf4_1631x463.png) > 说明: 设置表单字段配置。 方法:`field($field)` * 参数 **field** (必须) * 类型一:callable 闭包 // tab设置时$tab为切换栏key值,其余情况为null ```php field(function($tab){ $field = []; switch($tab){ case "base": $field = [ 'name'=>['title'=>'姓名','verify'=>'require|chsDash','desc'=>'只能输入汉字、字母、数字和下划线_及破折号-'], 'sex'=>[ 'title'=>'性别', 'type'=>'radio', 'verify'=>'require|in:man,woman', 'options'=>['man'=>'男','woman'=>'女'] ], ... ]; break; ... } return $field; }); ``` * 类型二:array ```php field([ 'name'=>['title'=>'姓名','verify'=>'require|chsDash','desc'=>'只能输入汉字、字母、数字和下划线_及破折号-'], 'sex'=>[ 'title'=>'性别', 'type'=>'radio', 'verify'=>'require|in:man,woman', 'options'=>['man'=>'男','woman'=>'女'] ], ... ]); ``` > 字段具体配置详见:[字段配置](https://www.kancloud.cn/worklz/yunj_admin_universal/2024522) > 示例: 设置`基础(base)`选项组为`中文姓名`+`英文姓名`+`性别`;`其他(other)`选项组为`年龄`+`年级`+`爱好`+`简介` * 方法如下: ~~~ $builder=YF('general_example') ->field(function($tab){ $field=[]; switch ($tab){ case 'base': $field=[ 'id'=>[ 'type'=>'hidden', 'value'=>$id ], 'name_cn'=>['title'=>'中文姓名','verify'=>'require|chs','desc'=>'只能输入汉字'], 'name_en'=>['title'=>'英文姓名','verify'=>'require|chsDash','desc'=>'只能输入汉字、字母、数字和下划线_及破折号-'], 'sex'=>[ 'title'=>'性别', 'type'=>'radio', 'verify'=>'require|in:man,woman', 'options'=>['man'=>'男','woman'=>'女'] ] ]; break; case 'other': $field=[ 'age'=>['title'=>'年龄','verify'=>'require|positiveInteger'], 'grade'=>[ 'title'=>'年级', 'type'=>'select', 'verify'=>'require|in:1,2,3,4', 'options'=>[1=>'一年级',2=>'二年级',3=>'三年级',4=>'四年级'] ], 'hobby'=>[ 'title'=>'爱好', 'type'=>'checkbox', 'verify'=>'require|arrayIn:write,read', 'value'=>['write','read'], 'options'=>['write'=>'写作','read'=>'阅读'] ], 'intro'=>[ 'title'=>'简介', 'type'=>'textarea', 'verify'=>'require', 'desc'=>'这是简介', ], ]; break; } return $field; }) ~~~