- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
function formSelect($itxt, $name = '', $val = array(), $selected = 0, $data = 0, $nullF = false, $atr = '', $optatr = array()) {
if(is_array($selected)) { $atr .= ' multiple'; }
$html = '<select name="'.$name.'" '.$atr.">\r\n";
if($nullF) {
$t = ($nullF === true) ? ' ' : $nullF;
$html .= '<option value="0">'.$t.'</option>'; }
if($data == 3) { $start = $itxt; $count = $val[0]; $step = $val[1]; }
else { $count = count($itxt); }
for($i = 0; $i < $count; $i++) {
// 4 - для быза данных
switch($data) {
case 1: $key = $val[$i]; $txt = $itxt[$i]; break;
case 2: $key = $i; $txt = $itxt[$i]; break;
case 3: $txt = $key = ($start + ($step*$i)); break;
case 4: $key = $itxt[$i][$val[0]]; $txt = $itxt[$i][$val[1]]; break;
default: $key = $txt = $itxt[$i]; break;
}
$sel = '';
if(is_array($selected)) {
if(in_array($key, $selected)) { $sel = 'selected'; }
} elseif($selected == $key) { $sel = 'selected'; }
if(!empty($optatr[$i])) { $opt = $optatr[$i]; } else { $opt = ''; }
$html .= '<option value="'.$key.'" '.$sel.$opt.'>'.$txt."</option>\r\n";
}
$html .= "</select>\r\n";
return $html;
}
Fike 20.07.2016 01:41 # 0
wvxvw 20.07.2016 08:45 # 0