diff options
Diffstat (limited to 'frontend/classes/form.php')
-rw-r--r-- | frontend/classes/form.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/frontend/classes/form.php b/frontend/classes/form.php new file mode 100644 index 0000000..51f548f --- /dev/null +++ b/frontend/classes/form.php @@ -0,0 +1,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); + } +} +?> |