fieldtype = TRUE; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... ) $this->defaulttype = 'VARCHAR'; // 当用户没有选择字段类型时的缺省值 } // 调出字段遍历出来 protected function _get_select_field($option, $field, $id, $at) { $str = '
'; foreach ($field as $t) { if ($t['disabled']) { continue; } elseif ($t['fieldtype'] == 'Merge') { continue; } elseif ($t['fieldtype'] == 'Group') { continue; } $str.= ''; } $str.= '
'; return $str; } /** * 字段相关属性参数 * * @param array $value 值 * @return string */ public function option($option, $field = NULL) { $data = dr_format_option_array($option['options']); if (!$data) { $ld = dr_lang('需要保存字段配置后才能配置联动关系'); } else { $ld = '
'; $ld.= ''; $ld.= ''; $ld.= ''; $ld.= ''; $ld.= ''; $ld.= ''; $ld.= ''; $ld.= ''; $data['dr_null'] = dr_lang('未选择时'); foreach ($data as $id => $name) { $ld.= ''; $ld.= ''; $ld.= ''; $ld.= ''; } $ld.= ''; $ld.= '
'.dr_lang('选项').''.dr_lang('隐藏字段').'
'.$name.''.$this->_get_select_field($option, $field, $id, 'hide').'
'; $ld.= '
'; } $option['options'] = isset($option['options']) ? $option['options'] : 'name1|1'.PHP_EOL.'name2|2'; return [ '
'.dr_lang('格式:选项名称|选项值[回车换行]选项名称2|值2....').' '.dr_lang('选项值建议使用从1开始的数字,不得带符号,也可以省略不写').'
   
'.dr_lang('开启后选项值被系统语言包翻译,否则就保持原样显示').'
'.$ld.' '.dr_lang('当选择某一个选项时会联动显示或隐藏指定的字段').'
'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'
'.$this->field_type($option['fieldtype'], $option['fieldlength']).'
' ]; } /** * 字段表单输入 * * @return string */ public function input($field, $value = '') { // 字段禁止修改时就返回显示字符串 if ($this->_not_edit($field, $value)) { return $this->show($field, $value); } // 字段存储名称 $name = $field['fieldname']; // 字段显示名称 $text = ($field['setting']['validate']['required'] ? ' * ' : '').dr_lang($field['name']); // 字段提示信息 $tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? ''.$field['setting']['validate']['tips'].'' : ''; // 字段默认值 $value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']); $str = ''; // 显示方式 $show_type = (int)$field['setting']['option']['show_type']; if ($field['setting']['option']['is_field_ld'] && $field['setting']['option']['field_ld']) { $str.= ''; $field['setting']['validate']['formattr'].= ' onclick="field_ld_'.$name.'(this.value)"'; } // 表单选项 $options = dr_format_option_array($field['setting']['option']['options']); if ($options) { foreach ($options as $v => $n) { $s = $v == $value ? ' checked' : ''; $kj = ''; $str.= ''; } } return $this->input_format($name, $text, '
'.$str.'
'.$tips); } /** * 字段表单显示 * * @param string $field 字段数组 * @param array $value 值 * @return string */ public function show($field, $value = null) { $options = dr_format_option_array($field['setting']['option']['options']); $str = '
'.(isset($options[$value]) ? dr_lang($options[$value]) : dr_lang('未选择')).'
'; return $this->input_format($field['fieldname'], $field['name'], $str); } }