Special Ops 2.50
[specialops2.git] / lib / HTML_Radiobutton.php
blob8b5bad64793f76384b7ad32043122d91ad359a05
1 <?php
2 /**
3 * HTML radio button object
5 * @author Ant P <p@cpi.merseine.nu>
6 * @license http://specialops.ath.cx/repos/so2/trunk/COPYING (New BSD Licence)
7 * @version 2.15
8 */
9 class HTML_Radiobutton
11 public $name;
12 public $label;
13 public $value;
14 public $checked;
16 function __construct($name, $label, $value = '', $checked = false)
18 $this->name = $name;
19 $this->label = $label;
20 $this->value = $value;
21 $this->checked = $checked;
24 function is_selected()
26 return isset($_POST[$this->name]) && $_POST[$this->name] == $this->value;
29 function __toString()
31 return '<label>'.
32 '<input type="radio" name="'.$this->name.'" value="'.$this->value.'"'.
33 ($this->checked ? ' checked="checked"' : '').'/>'.htmlspecialchars($this->label).'</label>';
36 static function factory($name, array $buttons, $default = null)
38 $ret = array();
39 foreach ( $buttons as $value => $label ) {
40 $ret[$value] = new HTML_Radiobutton($name, $label, $value, ($value==$default));
42 return $ret;