From 12a4e4d1ed827c59290838d5a11d75ad32aa28f1 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 8 May 2015 16:15:16 +0200 Subject: start of rewriting the form handling This is jsut a small beginning. Not all elements are there, yet. It's also completely untested so far. --- inc/Form/CheckableElement.php | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 inc/Form/CheckableElement.php (limited to 'inc/Form/CheckableElement.php') diff --git a/inc/Form/CheckableElement.php b/inc/Form/CheckableElement.php new file mode 100644 index 000000000..a57bbc1f6 --- /dev/null +++ b/inc/Form/CheckableElement.php @@ -0,0 +1,62 @@ +attr('value', 1); + } + + /** + * Handles the useInput flag and sets the checked attribute accordingly + */ + protected function prefillInput() { + global $INPUT; + list($name, $key) = $this->getInputName(); + $myvalue = $this->val(); + + if(!$INPUT->has($name)) return; + + if($key === null) { + // no key - single value + $value = $INPUT->str($name); + if($value == $myvalue) { + $this->attr('checked', 'checked'); + } else { + $this->rmattr('checked'); + } + } else { + // we have an array, there might be several values in it + $input = $INPUT->arr($name); + if(isset($input[$key])) { + $this->rmattr('checked'); + + // values seem to be in another sub array + if(is_array($input[$key])) { + $input = $input[$key]; + } + + foreach($input as $value) { + if($value == $myvalue) { + $this->attr('checked', 'checked'); + } + } + } + } + } + +} -- cgit v1.2.3