]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/form/Form.class.php
Resumed refactoring forms, hopefully without breaking reports this time.
[timetracker.git] / WEB-INF / lib / form / Form.class.php
index 6fb6ce1215cfb0cbad26b2efcba5bdcb4a63db92..a45b55a31d6c8abd44ca6bedddcc08defdba4e4f 100644 (file)
 // +----------------------------------------------------------------------+
 
 class Form {
-    var $formName      = "";
-       var $mAction       = "";
-       var $mMethod       = "post";
-       var $mEnctype      = "";
-       var $mId           = "";
-    var $error;
-       var $debugFunction;
-       var $mElements     = array();
+
+  var $name = '';
+  // TODO: refactoring ongoing down from here.
+
+       var $mElements = array();
        var $mRequest;
-//     var $mFormBean;
     
-    function Form($formid) {
-        $this->formName = $formid;
+    function __construct($formName) {
+        $this->name = $formName;
     }
     
     function setRequest(&$request) {
         $this->mRequest = &$request;
     }
-    
-/*    function setFormBean(&$bean) {
-        $this->mFormBean = &$bean;
-    }
-*/    
+
     function &getElement($name) {
        return $this->mElements[$name];
     }
@@ -72,20 +64,7 @@ class Form {
        // name
        // onsubmit
        // onreset
-       function setName($value) { $this->formName = $value; }
-    function getName() { return $this->formName; }
-    
-    function setId($value) { $this->mId = $value; }
-    function getId() { return $this->mId; }
-    
-    function setAction($value) { $this->mAction = $value; }
-    function getAction() { return $this->mAction; }
-    
-    function setMethod($value) { $this->mMethod = $value; }
-    function getMethod() { return $this->mMethod; }
-    
-    function setEnctype($value) { $this->mEnctype = $value; }
-    function getEnctype() { return $this->mEnctype; }
+    function getName() { return $this->name; }
     
     function isSubmit()        {
        if (!isset($this->mRequest)) return false;
@@ -102,15 +81,6 @@ class Form {
         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
@@ -126,18 +96,6 @@ class Form {
        // 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":
@@ -220,12 +178,9 @@ 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->formName);
+                       $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"]);
@@ -246,39 +201,27 @@ class Form {
        
        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->formName);
+                       $el->setFormName($this->name);
                        $this->mElements[$el->getName()] = &$el;
                }
        }
        
        
        function toStringOpenTag() {
-        $html = "<form name=\"$this->formName\"";
-        
-        if ($this->mId!="") 
-            $html .= " id=\"$this->mId\"";
-            
-        if ($this->mAction!="") 
-            $html .= " action=\"$this->mAction\"";
+        $html = "<form name=\"$this->name\"";
         
-        if ($this->mMethod!="") 
-            $html .= " method=\"$this->mMethod\"";
+        $html .= ' method="post"';
         
-        // for upload forms
+        // Add enctype for file upload forms.
         foreach ($this->mElements as $elname=>$el) {
-            if (strtolower(get_class($this->mElements[$elname]))=="uploadfile") {
-               $this->mEnctype = "multipart/form-data";
+            if (strtolower(get_class($this->mElements[$elname])) == 'uploadfile') {
+                $html .= ' enctype="multipart/form-data"';
+                break;
             }
         }
-        
-        if ($this->mEnctype!="")
-               $html .= " enctype=\"$this->mEnctype\"";
-        
+
         $html .= ">";
         return $html;
     }