分类:
2009-06-03 16:24:46
/*
* @copyright Copyright (c) 2007 ASEN (bbs.54php.com)
* @author 特蓝克斯
* @package Function
* @date 2007-09-11
* @return Array
* @Notes 处理表单 Options,Radio,Checkboxs 表单控件
*/
/**
*
* getOptions 参数列表:
* - result Options 数组
* - vals Options 数组修改的键值 (Value)
* - except Options 除"except"值外的数据调用
* - same Value和Title 值是否相同
* - exceptKey Options 除"exceptKey"键外的数据调用
*
* @return Array() $options
*/
function getOptions($result,$vals='whatthehellisthis',$except='',$same='',$exceptKey='') {
if(!$result) return false;
$options = "";
while(list($key,$val) = each($result)) {
$checkVal = false;
if($except) {
if(is_array($except)) $checkVal = in_array($val,$except);
else {
if($except == $val) $checkVal = true;
}
}
if($exceptKey) {
if(is_array($exceptKey)) $checkVal = in_array($key,$exceptKey);
else {
if($exceptKey == $key) $checkVal = true;
}
}
if(!$checkVal) {
if($same) $key = $val;
$options .= ";
if($key == $vals) $options .= " selected";
$options .= ">".$val."\n";
}
}
return $options;
}
/**
*
* getRadios 参数列表:
* - result Radio 数组
* - name Radio 名字
* - checked 默认选中第一个,通读索引控制 Radio 的 Checked 状态
* - vals 通过VALUE控制 Radio 的 Checked 状态
* - except Radios 除"except"值外的数据调用
* - enter 换行参数
* - Events 事件参数
* - style 样式参数
* - disabled 显示参数
* - exceptKey Radios 除"exceptKey"键外的数据调用
*
* @return Array() $radios
*/
function getRadios($result ,$name="radio" ,$checked='0' ,$vals='whatthehellisthis' ,$except='' ,$enter='0', $Events='' ,$style='border:solid 1 #FFFFFF;' ,$disabled='' ,$exceptKey='') {
if(!$result) return false;
$radios = '';
$i = 0;
foreach ($result as $key => $val) {
$checkVal = false;
if($except) {
if(is_array($except)) $checkVal = in_array($val,$except);
else {
if($except == $val) $checkVal = true;
}
}
if($exceptKey) {
if(is_array($exceptKey)) $checkVal = in_array($key,$exceptKey);
else {
if($exceptKey == $key) $checkVal = true;
}
}
if(!$checkVal) {
$radios .= ";
if($key == $vals) $radios .= " checked";
if ($checked != 'no' && $checked == $i) {
$radios .= " checked";
}
if ($disabled != "" && $disabled[$i] == 1) {
$radios .= " disabled";
}
$radios .= " style='".$style."' ".$Events.">".$val." ";
}
$i++;
if ($enter !=0 && ($i % $enter) ==0) {
$radios .="
";
}
}
return $radios;
}
/**
*
* getCheckboxs 参数列表:
* - result Checkbox 数组
* - name Checkbox 名字
* - checked 默认选中第一个,通读索引控制 Checkbox 的 Checked 状态
* - vals 通过VALUE控制 Checkbox 的 Checked 状态
* - except Checkboxs 除"except"值外的数据调用
* - enter 换行参数
* - Events 事件参数
* - style 样式参数
* - disabled 显示参数
* - exceptKey Checkboxs 除"exceptKey"键外的数据调用
*
* @return Array() $Checkboxs
*/
function getCheckboxs($result,$name='Checkboxs', $checked='0', $vals='whatthehellisthis',$except='',$enter='0',$Events='',$style='' ,$disabled='',$exceptKey='') {
if(!$result) return false;
$Checkboxs = "";
$i = 0;
foreach ($result as $key => $val) {
$checkVal = false;
if($except) {
if(is_array($except)) $checkVal = in_array($val,$except);
else {
if($except == $val) $checkVal = true;
}
}
if($exceptKey) {
if(is_array($exceptKey)) $checkVal = in_array($key,$exceptKey);
else {
if($exceptKey == $key) $checkVal = true;
}
}
if(!$checkVal) {
$Checkboxs .= ";
if(is_array($vals) && array_key_exists($key,$vals)) $Checkboxs .= " checked";
if(!is_array($vals) && $key == $vals) $Checkboxs .= " checked";
if ($checked != 'no' && $checked == $i) {
$Checkboxs .= " checked";
}
if ($disabled<>"" && $disabled[$i] ==1) {
$Checkboxs .= " disabled";
}
$Checkboxs .= " style=".$style." ".$Events.">".$val." ";
}
$i++;
if ($enter !=0 && ($i % $enter) ==0) {
$Checkboxs .="
";
}
}
return $Checkboxs;
}
?>examples Options 应用
/*
* @copyright Copyright (c) 2007 ASEN (bbs.54php.com)
* @author 特蓝克斯
* @package Function
* @date 2007-09-11
* @return Array
* @Notes 处理表单 Options 表单控件
*/
include_once "helpers_forms.php";
$arr_getoptions = array(
// 'key' => 'value',
'54_name' => "54master",
'54_title' => "网络编程",
'54_group' => "本版讨论群: 19870468"
);
$option = getOptions($arr_getoptions);
$option1 = getOptions($arr_getoptions, '', '网络编程');
$option2 = getOptions($arr_getoptions, "54_title");
$option3 = getOptions($arr_getoptions, "54_title", '',true);
$option4 = getOptions($arr_getoptions, '', '', '', '54_title');
?>
添加调用:
=$option?>
=$option?>
除VALUE值为"网络编程"的全部调用:
=$option1?>
=$option1?>
修改时调用:
=$option2?>
=$option2?>
value值和title值相等时 :
=$option3?>
=$option3?>
除KEY值为"54_title"全部调用:
=$option4?>
=$option4?>
examples Radio 应用
/*
* @copyright Copyright (c) 2007 ASEN (bbs.54php.com)
* @author 特蓝克斯
* @package Function
* @date 2007-09-11
* @return Array
* @Notes 处理表单 Radio 表单控件
*/
include_once "helpers_forms.php";
$arr_radio = array(
// 'key' => 'value',
'54_name' => "54master",
'54_title' => "网络编程",
'54_group' => "本版讨论群: 19870468"
);
$radio = getRadios($arr_radio);
$radio1 = getRadios($arr_radio,'radio1','no');
$radio2 = getRadios($arr_radio, 'radio2', 'no', '54_group');
$radio3 = getRadios($arr_radio, 'radio3', '', '' ,'网络编程');
$radio4 = getRadios($arr_radio, 'radio4', '', '' , '', '', '', '', '' ,'54_title');
?>
默认(选中第一个"radio"):
=$radio?>
=$radio?>
默认(选中补选任何一个"radio"):
=$radio1?>
=$radio1?>
修改:
=$radio2?>
=$radio2?>
除VALUE值为"网络编程"的全部调用:
=$radio3?>
=$radio3?>
除KEY值为"54_title"全部调用:
=$radio4?>
=$radio4?>
examples Checkbox应用
/*
* @copyright Copyright (c) 2007 ASEN (bbs.54php.com)
* @author 特蓝克斯
* @package Function
* @date 2007-09-11
* @return Array
* @Notes 处理表单 Checkbox 表单控件
*/
include_once "helpers_forms.php";
$arr_checkBox = array(
// 'key' => 'value',
'54_name' => "54master",
'54_title' => "网络编程",
'54_group' => "本版讨论群: 19870468"
);
$arr_values = array(
// 'key' => 'value',
'54_title' => "网络编程",
'54_group' => "本版讨论群: 19870468"
);
$Checkbox = getCheckboxs($arr_checkBox);
$Checkbox1 = getCheckboxs($arr_checkBox, 'checkbox1', 'no');
$Checkbox2 = getCheckboxs($arr_checkBox, 'checkbox2', 'no' , $arr_values);
$Checkbox3 = getCheckboxs($arr_checkBox, 'checkbox3', 'no' ,'54_title');
$Checkbox4 = getCheckboxs($arr_checkBox, 'checkbox4', 'no' , '' , '', '', '', '', '' ,'54_title');
$Checkbox5 = getCheckboxs($arr_checkBox, 'checkbox5', 'no' , '' , '网络编程');
?>
默认(选中第一个"checkbox"):
=$Checkbox?>
=$Checkbox?>
一个不选择
=$Checkbox1?>
=$Checkbox1?>
通过数组构造选中多个Checkbox
=$Checkbox2?>
=$Checkbox2?>
选中其中一个Checkbox元素
=$Checkbox3?>
=$Checkbox3?>
除KEY值为"54_title"全部调用:
=$Checkbox4?>
=$Checkbox4?>
除VALUE值为"网络编程"的全部调用:
=$Checkbox5?>
=$Checkbox5?>