- var $mMethod = "post";
- var $mEnctype = "";
- var $mId = "";
- var $error;
- var $debugFunction;
- var $mElements = array();
- var $mRequest;
-// var $mFormBean;
-
- function __construct($formid) {
- $this->name = $formid;
- }
-
- function setRequest(&$request) {
- $this->mRequest = &$request;
- }
-
-/* function setFormBean(&$bean) {
- $this->mFormBean = &$bean;
- }
-*/
- 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 setMethod($value) { $this->mMethod = $value; }
- function getMethod() { return $this->mMethod; }
-
- 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;
-
- case "datefield":
- import('form.DateField');
- $el = new DateField($arguments["name"]);
- $el->setMaxLength("10");
- break;
-
- case "floatfield":
- import('form.FloatField');
- $el = new FloatField($arguments["name"]);
- if (isset($arguments["format"])) $el->setFormat($arguments["format"]);
- break;
-
- case "textarea":
- import('form.TextArea');
- $el = new TextArea($arguments["name"]);
- $el->setColumns(@$arguments["cols"]);
- $el->setRows(@$arguments["rows"]);
- if (isset($arguments["maxlength"])) $el->setMaxLength($arguments["maxlength"]);
- break;
-
- case "checkbox":
- import('form.Checkbox');
- $el = new Checkbox($arguments["name"]);
- if (@$arguments["checked"]) $el->setChecked(true);
- $el->setData(@$arguments["data"]);
- 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($params) {
+ switch($params['type']) {
+ case 'text':
+ import('form.TextField');
+ $el = new TextField($params['name']);
+ if (isset($params['maxlength'])) $el->setMaxLength($params['maxlength']);
+ break;
+
+ case 'password':
+ import('form.PasswordField');
+ $el = new PasswordField($params['name']);
+ if (isset($params['maxlength'])) $el->setMaxLength($params['maxlength']);
+ break;
+
+ case 'datefield':
+ import('form.DateField');
+ $el = new DateField($params['name']);
+ $el->setMaxLength('10');
+ break;
+
+ case 'floatfield':
+ import('form.FloatField');
+ $el = new FloatField($params['name']);
+ if (isset($params['format'])) $el->setFormat($params['format']);
+ break;
+
+ case 'textarea':
+ import('form.TextArea');
+ $el = new TextArea($params['name']);
+ if (isset($params['cols'])) $el->setColumns($params['cols']);
+ if (isset($params['rows'])) $el->setRows($params['rows']);
+ if (isset($params['maxlength'])) $el->setMaxLength($params['maxlength']);
+ break;
+
+ case 'checkbox':
+ import('form.Checkbox');
+ $el = new Checkbox($params['name']);
+ break;
+
+// TODO: refactoring ongoing down from here.