Too many changes to all list here, biggest ones:
[specialops2.git] / lib / class.form_select.php
blobcb2a15a1c4c4fbbe22a8e4b3b1e3ee8e6ddc20b3
1 <?php
2 // $Id$
4 class form_select
6 public $name;
7 public $indent;
8 public $default;
9 public $attributes;
10 private $values = array();
12 function __construct($name, $indent = 0, $default = null, $attributes = array())
14 $this->name = $name;
15 $this->indent = $indent;
16 $this->default = $default;
17 $this->attributes = $attributes;
20 function add_item($value, $name = '')
22 if ( !$name )
23 $name = $value;
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);
38 function display()
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.'"';
45 $out .= ">\n";
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";
50 return $out;