X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=WEB-INF%2Flib%2Fform%2FForm.class.php;h=ceaed430c414435dc07561b1e10b3e2f673fe6f3;hb=3a5964df63eb410b66e02326ebc7f7c90e8d606e;hp=4d6987f6006b49137146c153812970058459c3ac;hpb=8c194ac6af2accb4f45e35e93629037a0983cc3f;p=timetracker.git diff --git a/WEB-INF/lib/form/Form.class.php b/WEB-INF/lib/form/Form.class.php index 4d6987f6..ceaed430 100644 --- a/WEB-INF/lib/form/Form.class.php +++ b/WEB-INF/lib/form/Form.class.php @@ -36,105 +36,35 @@ class Form { var $name = ''; - // TODO: refactoring ongoing down from here. + var $elements = array(); - var $mEnctype = ""; - var $mId = ""; - var $error; - var $debugFunction; - var $mElements = array(); - var $mRequest; - - function __construct($formid) { - $this->name = $formid; - } - - function setRequest(&$request) { - $this->mRequest = &$request; - } + function __construct($formName) { + $this->name = $formName; + } - function &getElement($name) { - return $this->mElements[$name]; - } - - function &getElements() { - return $this->mElements; - } - - //// FORM element - // action - // method - GET, POST - // enctype - enctype="multipart/form-data" - // name - // onsubmit - // onreset - function setName($value) { $this->name = $value; } - function getName() { return $this->name; } - - function setId($value) { $this->mId = $value; } - function getId() { return $this->mId; } - - function isSubmit() { - if (!isset($this->mRequest)) return false; - $result = false; - foreach ($this->mElements as $el) { - if (strtolower(get_class($el))=="submit") { - $name = $el->getName(); - $value = $this->mRequest->getAttribute($name); - if($value) { - $result = true; - } - } - } - return $result; - } - - function OutputError($error,$scope="") - { - $this->error=(strcmp($scope,"") ? $scope.": ".$error : $error); - if(strcmp($function=$this->debugFunction,"") - && strcmp($this->error,"")) - $function($this->error); - return($this->error); - } - - //// INPUT element - // type = TEXT | PASSWORD | CHECKBOX | RADIO | SUBMIT | RESET | FILE | HIDDEN | IMAGE | BUTTON - // name - // value - // checked - for type radio and checkbox - // size - width pixels or chars - // maxlength - // src - for type image - // tabindex - support A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA - // accesskey - support A, AREA, BUTTON, INPUT, LABEL, and LEGEND, and TEXTAREA - // onfocus - // onblur - // onselect - INPUT and TEXTAREA - // onchange - function addInput($arguments) { - if(strcmp(gettype($arguments),"array")) - $this->OutputError("arguments must be array","AddInput"); - - if(!isset($arguments["type"]) || !strcmp($arguments["type"],"")) - return($this->OutputError("Type not defined","AddInput")); - - if(!isset($arguments["name"]) || !strcmp($arguments["name"],"")) - return($this->OutputError("Name of element not defined","AddInput")); - - if (isset($this->mElements[$arguments["name"]])) - return($this->OutputError("it was specified '".$arguments["name"]."' name of an already defined input","AddInput")); - - switch($arguments["type"]) { - - case "textfield": - case "text": - import('form.TextField'); - $el = new TextField($arguments["name"]); - $el->setMaxLength(@$arguments["maxlength"]); - if (isset($arguments["aspassword"])) $el->setAsPassword($arguments["aspassword"]); - break; - + function getElement($name) { + return $this->elements[$name]; + } + + function getElements() { + return $this->elements; + } + + function getName() { return $this->name; } + + // addInput - adds an input object to the form. + function addInput($arguments) { + switch($arguments['type']) { + case 'text': + import('form.TextField'); + $el = new TextField($arguments['name']); + $el->setMaxLength(@$arguments['maxlength']); + if (isset($arguments['aspassword'])) $el->setAsPassword($arguments['aspassword']); + break; + +// TODO: refactoring ongoing down from here. +// aspassword - change this name to something better? Perhaps. +// Change $arguments to something better too (maybe). $args or $params? case "datefield": import('form.DateField'); $el = new DateField($arguments["name"]); @@ -207,16 +137,12 @@ class Form { $el = new UploadFile($arguments["name"]); if (isset($arguments["maxsize"])) $el->setMaxSize($arguments["maxsize"]); break; - - default: - return($this->OutputError("Type not found for input element","AddInput")); } if ($el!=null) { $el->setFormName($this->name); if (isset($arguments["id"])) $el->setId($arguments["id"]); if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]); - if (isset($arguments["render"])) $el->setRenderable($arguments["render"]); - if (isset($arguments["enable"])) $el->setEnable($arguments["enable"]); + if (isset($arguments["enable"])) $el->setEnabled($arguments["enable"]); if (isset($arguments["style"])) $el->setStyle($arguments["style"]); if (isset($arguments["size"])) $el->setSize($arguments["size"]); @@ -227,19 +153,16 @@ class Form { if (isset($arguments["onchange"])) $el->setOnChange($arguments["onchange"]); if (isset($arguments["onclick"])) $el->setOnClick($arguments["onclick"]); - $this->mElements[$arguments["name"]] = &$el; + $this->elements[$arguments["name"]] = &$el; } } function addInputElement(&$el) { if ($el && is_object($el)) { - if (!$el->getName()) - return($this->OutputError("no name in element","addInputElement")); - if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]); $el->setFormName($this->name); - $this->mElements[$el->getName()] = &$el; + $this->elements[$el->name] = &$el; } } @@ -247,30 +170,25 @@ class Form { function toStringOpenTag() { $html = "
"; @@ -282,21 +200,21 @@ class Form { $vars['open'] = $this->toStringOpenTag(); $vars['close'] = $this->toStringCloseTag(); - foreach ($this->mElements as $elname=>$el) { - if (is_object($this->mElements[$elname])) - $vars[$elname] = $this->mElements[$elname]->toArray(); + foreach ($this->elements as $elname=>$el) { + if (is_object($this->elements[$elname])) + $vars[$elname] = $this->elements[$elname]->toArray(); } //print_r($vars); return $vars; } function getValueByElement($elname) { - return $this->mElements[$elname]->getValue(); + return $this->elements[$elname]->getValue(); } function setValueByElement($elname, $value) { - if (isset($this->mElements[$elname])) { - $this->mElements[$elname]->setValue($value); + if (isset($this->elements[$elname])) { + $this->elements[$elname]->setValue($value); } } }