1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<?php
class form {
protected $elements=array();
function output($rw=true, $vals=array()) {
foreach ($this->elements as $name => &$el) {
if (is_object($el)) {
if (!$el->status)
echo print_warning('Please complete this field:');
$el->output($rw, isset($vals[$name])?$vals[$name]:false);
} else {
echo $el;
}
}
}
function process() {
$vals=array();
foreach ($this->elements as $name => &$el) {
if (!is_object($el)) continue;
$vals[$name]=$el->process();
$el->status=$vals[$name] !== false;
}
return $vals;
}
function verify($vals) {
foreach ($this->elements as $name => &$el) {
if (!is_object($el)) continue;
if (!isset($vals[$name]))
return null;
elseif (!($el->status=$el->verify($vals[$name])))
return false;
}
return true;
}
public function text($text) {
$this->elements[]=$text;
}
public function text_input($optname, $htmlname, $label) {
$this->elements[$optname]=new text_input($htmlname, $label);
}
public function select($optname, $htmlname, $label, $options) {
$this->elements[$optname]=new select($htmlname, $label, $options);
}
public function radio_array($optname, $htmlname, $label, $options) {
$this->elements[$optname]=new radio_array($htmlname, $label, $options);
}
public function checkbox_array($optname, $htmlname, $label, $array, $delim=' ') {
$this->elements[$optname]=new checkbox_array($htmlname, $label, $array, $delim=' ');
}
public function layered_checkbox_array($optname, $htmlname, $label, &$array, $delim=' ', $metadata) {
$this->elements[$optname]=new layered_checkbox_array($htmlname, $label, $array, $delim, $metadata);
}
}
?>
|