10 private $values = array();
12 function __construct($name, $indent = 0, $default = null, $attributes = array())
15 $this->indent
= $indent;
16 $this->default = $default;
17 $this->attributes
= $attributes;
20 function add_item($value, $name = '')
24 $this->values
[$value] = $name;
27 function set_default($value)
29 $this->default = $value;
32 function check_value(&$value)
34 if ( !isset($value) ||
!isset($this->values
[$value]) )
35 throw new OutOfBoundsException('Bad value given for selectbox "'.$this->name
.'": '.$value);
40 $t = str_repeat("\t", $this->indent
);
42 $out = "\n$t".'<select name="'.$this->name
.'"';
43 foreach ( $this->attributes
as $name => $value )
44 $out .= ' '.$name.'="'.$value.'"';
46 foreach ( $this->values
as $value => $name )
47 $out .= "$t\t".'<option value="'.$value.'"'.( $value == $this->default ?
' selected="selected"' : '' ).'>'.$name."</option>\n";
48 $out .= "$t</select>\n";