/** * 返回集成表单 * @param string $name 元素名称 * @param integer $typeid 类型 * @param string $tvalue 表单类型和可选值 * @param string|integer $vaule 值 * @return mixed */ function get_element_html($name,$typeid, $tvalue = '', $vaule = '') { if (empty($name) || empty($typeid)) { return ''; } //表单类型 switch ($typeid) { case 1: $type = 'text'; $vaule = intval($vaule); break; case 2: $type = 'text'; break; case 3: $type = 'textarea'; break; case 4: $type = 'radio'; $vaule = intval($vaule); break; default: $type = 'text'; break; } if (!empty($tvalue)) { $array = explode("\n", str_replace("\r\n", "\n", trim($tvalue,"\r\n"))); if (in_array($array[0], array('select','radio','checkbox','text','textarea'))) { $type = $array[0]; //select radio checkbox text textarea unset($array[0]); if(strpos($tvalue,'|')){ $tvalue = array(); foreach ($array as $val) { // 0|原图等比例缩略 // 1|固定大小截取 list($k, $v) = explode('|', $val); //$k 等于 0、1 //$v 等于 原图等比例缩略、固定大小截取 $tvalue[$k] = $v; } }else{ foreach ($array as $val) { // select $tvalue[$val] = $val; } } }else { } } $str = ''; //类型 text、textarea、radio、select、checkbox switch ($type) { case 'text': $str = '<input type="text" class="inp_large" name="'.$name.'" value="'.$vaule.'">'; break; case 'textarea': $str = '<textarea name="'.$name.'" id="'.$name.'" class="tarea_default">'.$vaule.'</textarea>'; break; case 'radio': //没有$tvalue 设置默认值 if (!is_array($tvalue)) { $tvalue = array(1=>'是',0=>'否'); } foreach ($tvalue as $k => $v) { $str .= '<input type="radio" name="'.$name.'" value="'.$k.'" '; if ($vaule == $k) { $str .= 'checked="checked" '; } $str .='/>'.$v.' '; } break; case 'checkbox': if (!is_array($tvalue)) { break; } foreach ($tvalue as $k => $v) { $str .= '<input type="checkbox" name="'.$name.'" value="'.$k.'" '; if ($vaule == $k) { $str .= 'checked="checked" '; } $str .='/>'.$v.' '; } break; case 'select': if (!is_array($tvalue) && false !== strpos($name, 'CFG_THEMESTYLE')) { $tmp = get_file_folder_List('./Public/Home/' , 1); $tvalue = array(); foreach ($tmp as $key => $value) { $tvalue[$value] = $value; } }elseif (!is_array($tvalue) && false !== strpos($name, 'CFG_MOBILE_THEMESTYLE')) { $tmp = get_file_folder_List('./Public/Mobile/' , 1); $tvalue = array(); foreach ($tmp as $key => $value) { $tvalue[$value] = $value; } } if (!is_array($tvalue)) { $tvalue = array(); } $str .= '<select name="'.$name.'">'; foreach ($tvalue as $k => $v) { $str .= '<option value="'.$k.'" '; if ($vaule == $k) { $str .= 'selected="selected" '; } $str .='>'.$v.'</option>'; } $str .= '</select>'; break; default: $str = ''; break; } return $str; } 后台调用: {:get_element_html("config[".$config['name']."]",$config['typeid'], $config['tvalue'], $config['value'])}
数据库设计: