Special Ops 2.50
[specialops2.git] / lib / HTML_Input.php
blob9747ac1be21a781cc3eb7fb71efb3f7f63a23db6
1 <?php
2 /**
3 * Object-oriented HTML input field with validation
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_Input
11 public $name;
12 public $value;
13 public $maxlength;
15 function __construct($name, $value = '', $length = 20)
17 $this->name = $name;
18 $this->value = $value;
19 $this->maxlength = $length;
22 function check_value()
24 if ( ! isset($_POST[$this->name])
25 or $this->maxlength && strlen($_POST[$this->name]) > $this->maxlength ) {
26 throw new OutOfBoundsException('Bad or no value given for form field "'.$this->name);
31 function toString()
33 $field = '<input type="text"';
35 foreach ( $this as $k => $v )
36 if ( ! empty($k) )
37 $field .= " $k=\"$v\"";
39 if ( is_null($this->default) && isset($_POST[$this->name]) )
40 $field .= ' value="'.$_POST[$this->name].'"';
42 return $field.'/>';