Date: 12/11/00
- Next message: uw: "[phplib-dev] cvs commit"
- Previous message: uw: "[phplib-dev] cvs commit"
- Next in thread: uw: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: uw
Date: Mon Dec 11 20:18:20 2000
Modified files:
php-lib/php/form/form.inc
php-lib/php/form/form_baseobject.inc
php-lib/php/form/form_copiedapi.inc
php-lib/php/form/form_element.inc
php-lib/php/form/form_element_buttonobject.inc
php-lib/php/form/form_element_checkbox.inc
php-lib/php/form/form_element_checkobject.inc
php-lib/php/form/form_element_combo.inc
php-lib/php/form/form_element_date.inc
php-lib/php/form/form_element_file.inc
php-lib/php/form/form_element_fileupload.inc
php-lib/php/form/form_element_hidden.inc
php-lib/php/form/form_element_image.inc
php-lib/php/form/form_element_password.inc
php-lib/php/form/form_element_radio.inc
php-lib/php/form/form_element_reset.inc
php-lib/php/form/form_element_select.inc
php-lib/php/form/form_element_selectobject.inc
php-lib/php/form/form_element_submit.inc
php-lib/php/form/form_element_text.inc
php-lib/php/form/form_element_textarea.inc
php-lib/php/form/form_element_textobject.inc
php-lib/php/form/form_element_tree.inc
php-lib/php/form/form_object.inc
Log message:
- code beautified
- same with IT[X]: forget PHP 3 - now PHP 4 only!
Be warned: I did not test the sources. Likely to be broken.
Index: php-lib/php/form/form.inc
diff -u php-lib/php/form/form.inc:1.9 php-lib/php/form/form.inc:1.10
--- php-lib/php/form/form.inc:1.9 Thu Jun 22 11:13:00 2000
+++ php-lib/php/form/form.inc Mon Dec 11 20:17:48 2000
@@ -1,67 +1,65 @@
<?php
/**
* Public methods of the form class.
-* <email protected> Ulf Wendel <ulf <email protected>>
-* <email protected> 0.1
+*
+* <email protected> Ulf Wendel <ulf.wendel <email protected>>
+* <email protected> $Id: form.inc,v 1.10 2000/12/11 19:17:48 uw Exp $
+* <email protected> Form
*/
class form extends form_copiedapi {
-
+
/**
- * Set the JavaScript mode
+ * Sets the JavaScript validation mode.
+ *
* <email protected> $js_mode = "weak"
* <email protected> public
*/
- function setJSMode($js_mode="weak") {
-
- if (""!=$js_mode && "strong"==strtolower($js_mode))
- $this->js_mode = "strong";
- else
- $this->js_mode = "weak";
-
+ function setJSMode($js_mode = "weak") {
+ $this->js_mode = ("weak" == strtolower($js_mode)) ? "weak" : "strong";
} // end func setJSMode
/**
- * set the method used by this form
+ * Sets the method used by this form.
+ *
* <email protected> string $method
* <email protected> public
* <email protected> autoloadValues(), method
*/
- function setMethod($method="POST") {
- if ("POST"!=strtoupper($method))
- $method = "GET";
- $this->method = $method;
+ function setMethod($method = "POST") {
+ $this->method = ("GET" == strtoupper($method)) ? "GET" : "POST";
} // end func setMethod
/**
* Loads the form with HTTP_[POST|GET]_VARS
+ *
* <email protected> array $ellist
* <email protected> bool $ok
* <email protected> public
*/
- function autoloadValues($ellist="") {
+ function autoloadValues($ellist = "") {
- if (""==$ellist)
+ if ("" == $ellist)
$ellist = $this->getElementnames();
+
if (!is_array($ellist))
$ellist = array($ellist);
- if (!is_array($ellist) || 0==count($ellist)) {
- $this->exception = new InvalidParameterException("Can't load the form with submitted values, no elements in form or no elements given.", __FILE__, __LINE__);
+ if (!is_array($ellist) || 0 == count($ellist)) {
+ $this->exceptions[] = new FormError("Can't load the form with submitted values, no elements in form or no elements given.", __FILE__, __LINE__);
return false;
}
- $data = ("POST" == $this->method) ? $GLOBALS["HTTP_POST_VARS"] : $GLOBALS["HTTP_GET_VARS"];
- if (!is_array($data) || 0==count($data)) {
- $this->exception = new FormException("Can't find any HTTP_$this->method_VARS.", __FILE__, __LINE__);
+ $data = ("GET" == $this->method) ? &$GLOBALS["HTTP_GET_VARS"] : &$GLOBALS["HTTP_POST_VARS"];
+ if (!is_array($data) || 0 == count($data)) {
+ $this->exceptions[] = new FormError("Can't find any HTTP_$this->method_VARS.", __FILE__, __LINE__);
return true;
}
- reset($ellist);
- while (list($k, $name)=each($ellist)) {
- $el = $this->elements[$name];
- $http_x_name = $el->name;
+ foreach ($ellist as $k => $name) {
- if ("]"==substr($http_x_name, -1) && $start=strpos($http_x_name, "[")) {
+ $http_x_name = $this->elements[$name]->name;
+
+ if ("]" == substr($http_x_name, -1) && $start = strpos($http_x_name, "[")) {
// The element name looks something like 'foo[x]'. We can't test
// "isset($http_x_vars["foo[x]"])", we have to translate it
@@ -69,10 +67,10 @@
preg_match_all("/\[([a-zA-Z0-9_]+)\]/", $http_x_name, $regs, PREG_SET_ORDER);
$index = sprintf('["%s"]', substr($http_x_name, 0, $start));
- reset($regs);
- while (list($k, $match)=each($regs))
- if ('"'!=substr($match[1], 1) && '"'!=substr($match[1], -1))
- $index.= sprintf('["%s"]', $match[1]);
+
+ foreach ($regs as $k => $match)
+ if ('"' != substr($match[1], 1) && '"' != substr($match[1], -1))
+ $index .= sprintf('["%s"]', $match[1]);
$code = sprintf('$ok = isset($data%s);', $index);
// If you script dies on this line, you've choosed an illegal element name
@@ -84,26 +82,23 @@
eval($code);
} else {
+
if (!isset($data[$http_x_name]))
continue;
+
$value = $data[$http_x_name];
+
}
if (isset($this->elements[$name])) {
- $el = $this->elements[$name];
- $el->setValue($value);
- $this->elements[$name] = $el;
+ $this->elements[$name]->setValue($value);
} else if (isset($this->radio_elements[$name])) {
$elements = $this->radio_elements[$name];
- reset($elements);
- while (list($elname, $v)=each($elements)) {
- $el = $this->elements[$elname];
- $el->setValue($value);
- $this->elements[$elname] = $el;
- }
+ foreach($this->radio_elements[$name] as $elname => $v)
+ $this->elements[$elname]->setValue($value);
}
@@ -114,35 +109,28 @@
/**
* Sets the value of one element or a group of elements.
+ *
* <email protected> array $value Array of values, $values[ name ] = value
* <email protected> boolean $ok
- * <email protected> InvalidParameterException
+ * <email protected> FormError
* <email protected> public
*/
function setValues($values) {
- if (!is_array($values) || 0==count($values)) {
- $this->exception = new InvalidParameterException("No values give.", __FILE__, __LINE__);
+ if (!is_array($values) || 0 == count($values)) {
+ $this->exceptions[] = new FormError("No values give.", __FILE__, __LINE__);
return false;
}
$ok = true;
- reset($values);
- while (list($name, $value)=each($values))
+ foreach ($values as $name => $value)
if (isset($this->elements[$name])) {
-
- $el = $this->elements[$name];
- $el->setValue($value);
- $this->elements[$name] = $el;
+
+ $this->elements[$name]->setValue($value);
} else if (isset($this->radio_elements[$name])) {
- $elements = $this->radio_elements[$name];
- reset($elements);
- while (list($elname, $v)=each($elements)) {
- $el = $this->elements[$elname];
- $el->setValue($value);
- $this->elements[$elname] = $el;
- }
+ foreach ($this->radio_elements[$name] as $elname => $v)
+ $this->elements[$elname]->setValue($value);
} else
$ok = false;
@@ -163,42 +151,33 @@
* array of elements: $ellist [ name ] = events.
* <email protected> boolean $status The default of false turns off the validation,
* true turns it on.
- * <email protected> boolean $ok
* <email protected> ValidationOn(), ValidationOff()
*/
- function Validation($ellist, $status=false) {
+ function Validation($ellist, $status = false) {
if (!is_array($ellist))
$ellist = array ( $ellist => "all" );
- if (false!=$status)
+ if (false != $status)
$status = true;
- reset($ellist);
- while (list($name, $events)=each($ellist))
+ foreach ($ellist as $name => $events)
if (isset($this->elements[$name])) {
- $el = $this->elements[$name];
- $el->react($events, $status);
- $this->elements[$name] = $el;
+ $el = $this->elements[$name]->react($events, $status);
} else if (isset($this->radio_elements[$name])) {
- $elements = $this->radio_elements[$name];
- reset($elements);
- while (list($elname, $v)=each($elements)) {
- $el = $this->elements[$elname];
- $el->react($events, $status);
- $this->elements[$name] = $el;
- }
+ foreach ($this->radio_elements[$name] as $elname => $v)
+ $this->elements[$elname]->react($events, $status);
}
- return true;
} // end func Validation
/**
* Public handle to turn default validation off.
+ *
* <email protected> mixed $ellist Name of one element or array of elements.
* <email protected> Validation
* <email protected> public
@@ -209,7 +188,8 @@
} // end func ValidatorOff
/**
- * Public handle to turn default validation on
+ * Public handle to turn default validation on.
+ *
* <email protected> mixed $ellist Name of one element or array of elements.
* <email protected> Validation
* <email protected> ValidationOff()
@@ -221,31 +201,31 @@
/**
* Sets the name of a custom validation function.
+ *
* <email protected> string $name element name
* <email protected> string $validator name of validation function
- * <email protected> boolean $ok
- * <email protected> FormNoSuchElement,
+ * <email protected> FormError
+ * <email protected> boolean
*/
function setValidator($name, $validator) {
- if (!$this->ElementExists($name) {
- $this->exception = new FormNoSuchElement("'$name' is not a known element", __FILE__, __LINE__);
+ if (!$this->ElementExists($name)) {
+ $this->exceptions[] = new FormError("'$name' is not a known element", __FILE__, __LINE__);
return false;
}
- if (!isset($this[$validator]) || "userfunction" != gettype($this[$validator]) ) {
- $this->exception = new FormException("Can't find the method '$validator'", __FILE__, __LINE__);
+ if (!method_exists($this, $validator)) {
+ $this->exceptions[] = new FormError("Can't find the method '$validator'", __FILE__, __LINE__);
return false;
}
- $el = $this->elements[$name];
- $ok = $el->setValidator($validator);
- $this->elements[$name] = $el;
+ $this->elements[$name]->setValidator($validator);
- return $ok;
+ return true;
} // end func setValidator
/**
* Generates the opening HTML form tag, <form>.
+ *
* <email protected> string $js_name = ""
* <email protected> enum(POST|GET) $method = "POST"
* <email protected> string $action = ""
@@ -254,48 +234,40 @@
* <email protected> string $html
* <email protected> public
*/
- function getStart($js_name="", $method="POST", $action="", $target="", $form_name="") {
+ function getStart($js_name = "", $method = "POST", $action = "", $target = "", $form_name = "") {
global $PHP_SELF;
- $html = "";
-
- $html.= sprintf('<form action="%s" target="%s" ',
- (""==$action) ? $PHP_SELF : $action,
- (""==$target) ? "_self" : $target
+ $html = sprintf('<form action="%s" target="%s" ',
+ ("" == $action) ? $PHP_SELF : $action,
+ ("" == $target) ? "_self" : $target
);
- $html.= sprintf('method="%s" ', ("GET"==strtoupper($method)) ? "GET" : "POST" );
+ $html .= sprintf('method="%s" ', ("GET" == strtoupper($method)) ? "GET" : "POST" );
+
if ($this->flag_file) {
- $html.= 'enctype="multipart/form-data" ';
+ $html .= 'enctype="multipart/form-data" ';
$method = "POST";
}
+
$this->setMethod($method);
- if (""!=$js_name) {
+ if ("" != $js_name) {
$this->js_name = $js_name;
- $html.= sprintf('name="%s" onSubmit="return %s_Validator(this, \'\')" ',
+ $html .= sprintf('name="%s" onSubmit="return %s_Validator(this, \'\')" ',
$js_name,
$js_name
);
}
- $html = substr($html, 0, -1);
- $html.=">".$this->CR_HTML;
-
- return $html;
+ return substr($html, 0, -1) . ">" . $this->CR_HTML;
} // end fun getStart
/**
* Generate and print <form>-Tag
- * <email protected> string $js_name = ""
- * <email protected> enum(POST|GET) $method = "POST"
- * <email protected> string $action = ""
- * <email protected> string $target = ""
- * <email protected> string $form_name = ""
- * <email protected> string $html
- * <email protected> public
+ *
+ * <email protected> getStart()
*/
- function Start($js_name="", $method="POST", $action="", $target="", $form_name="") {
+ function Start($js_name = "", $method = "POST", $action = "", $target = "", $form_name = "") {
$html = $this->getStart($js_name, $method, $action, $target, $form_name);
print $html;
return $html;
@@ -303,52 +275,50 @@
/**
* Generates the closing HTML form tag and handles the hidden elements.
+ *
* <email protected> string $additional_html Optional, additional HTML inserted in front of
* the generated HTML.
* <email protected> string $html
* <email protected> public
*/
- function getFinish($additional_html="") {
+ function getFinish($additional_html = "") {
$html = $additional_html;
- if (0!=count($this->hidden_elements)) {
- reset($this->hidden_elements);
- while (list(, $elname)=each($this->hidden_elements))
- $html.= $this->getElement($elname);
+ if (0 != count($this->hidden_elements)) {
+ foreach ($this->hidden_elements as $k => $elname)
+ $html .= $this->getElement($elname);
}
- $html.= "</form>".$this->CR_HTML;
+ $html .= "</form>" . $this->CR_HTML;
- if (""!=$this->js_name) {
- $html.= $this->getJSHead();
-
- reset($this->elements);
- while (list($name, $el)=each($this->elements)) {
+ if ("" != $this->js_name) {
+
+ $html .= $this->getJSHead();
+
+ foreach ($this->elements as $name => $el)
$html.= $el->getJS();
- }
- $html.= $this->getJSFoot();
+ $html .= $this->getJSFoot();
}
return $html;
} // end func getFinish
/**
- * Generate and print closing </form>-Tag
- * <email protected> string $additional_html
- * <email protected> object $sess = ""
- * <email protected> string $html
- * <email protected> public
+ * Generate and print closing </form>-Tag.
+ *
+ * <email protected> getFinish()
*/
- function Finish($additional_html="", $sess="") {
- $html = $this->getFinish($additional_html, $sess="");
+ function Finish($additional_html = "", $sess = "") {
+ $html = $this->getFinish($additional_html, $sess);
print $html;
return $html;
} // end func Finish
/**
- * Generate the complete form
+ * Generate the complete form.
+ *
* <email protected> string $js_name = ""
* <email protected> enum(POST|GET) = "POST"
* <email protected> string $action = $PHP_SELF
@@ -359,19 +329,16 @@
* <email protected> getStart(), getFinish()
* <email protected> public
*/
- function get($js_name="", $method="POST", $action="", $target="", $form_name="", $additional_html) {
- $html = $this->getStart($js_name, $method, $action, $target, $form_name);
- $html.= $this->getFinish($additional_html);
- return $html;
+ function get($js_name = "", $method = "POST", $action = "", $target = "", $form_name = "", $additional_html) {
+ return $this->getStart($js_name, $method, $action, $target, $form_name) . $this->getFinish($additional_html);
} // end func get
/**
- * Generate and print the complete form
- * <email protected> get, getStart(), getFinish()
- * <email protected> public
- * <email protected> string $html
+ * Generate and print the complete form.
+ *
+ * <email protected> get()
*/
- function show($js_name="", $method="POST", $action="", $target="", $form_name="", $additional_html) {
+ function show($js_name = "", $method = "POST", $action = "", $target = "", $form_name = "", $additional_html) {
$html = $this->get($js_name, $method, $action, $target, $form_name, $additional_html);
print $html;
return $html;
@@ -379,13 +346,15 @@
/**
* Adds an element to the form object.
+ *
* <email protected> array $element_data
* <email protected> bool $ok
* <email protected> public
+ * <email protected> FormError
*/
function addElement($element_data) {
- if (""==$element_data || (is_array($element_data) && 0==count($element_data)) ) {
- $this->exception = new InvalidParameterException("No element data given.", __FILE__, __LINE__);
+ if ("" == $element_data || (is_array($element_data) && 0 == count($element_data)) ) {
+ $this->exceptions[] = new FormError("No element data given.", __FILE__, __LINE__);
return false;
}
@@ -395,116 +364,114 @@
$this->addDefaultAttributes($element_data);
// Generate Object
- $of_objectname = "form_element_".$element_data["type"];
+ $of_objectname = "form_element_" . $element_data["type"];
$el = new $of_objectname( $element_data, $this->method, $this->js_name, $this->js_mode );
if (!$el->flag_config_ok)
return false;
- if ("hidden" == $element_data["type"])
+ if ($el->isHidden())
$this->hidden_elements[] = $element_data["name"];
if (isset($element_data["elname"])) {
+
$this->elements[$element_data["elname"]] = $el;
+ $this->element_names[$element_data["elname"]] = $element_data["elname"];
+
if ("radio" == $element_data["type"] )
$this->radio_elements[$el->name][$element_data["elname"]] = $el->value;
- } else
+
+ } else {
+
$this->elements[$el->name] = $el;
+ $this->element_names[$el->name] = $el->name;
+
+ }
return true;
} // end func addElement
/**
- * Generate and return the html of an element
+ * Generate and return the html representation of an element.
+ *
* <email protected> string $elname
* <email protected> string $value, only used with radio!
* <email protected> string $html
- * <email protected> FormNoSuchElement
+ * <email protected> FormError
* <email protected> public
*/
- function getElement($elname, $value="") {
+ function getElement($elname, $value = "") {
- if (!$this->ElementExists($elname) {
- $this->exception = FormNoSuchElement("'$elname' is unknown.", __FILE__, __LINE__);
+ if (!$this->ElementExists($elname)) {
+ $this->exceptions[] = new FormError("'$elname' is unknown.", __FILE__, __LINE__);
return "";
}
- if (!isset($this->radio_elements[$elname])) {
- $el = $this->elements[$elname];
- return $el->get($value);
- }
+ if (!isset($this->radio_elements[$elname]))
+ return $this->elements[$elname]->get($value);
$html = "";
- $elements = $this->radio_elements[$elname];
- reset($elements);
- while (list($elname, $v)=each($elements)) {
- $el = $this->elements[$elname];
- $html.= $el->get($value);
- }
+ foreach ($this->radio_elements[$elname] as $name => $v)
+ $html .= $this->elements[$name]->get($value):
return $html;
} // end func getElement
/**
* Return the type of an element.
+ *
* <email protected> string $elname
* <email protected> string $type
- * <email protected> FormNoSuchElement
+ * <email protected> FormError
* <email protected> public
*/
function getType($elname) {
if (!$this->ElementExists($elname)) {
- $this->exception = new FormNoSuchElement("'$elname' is unknown", __FILE__, __LINE__);
+ $this->exceptions[] = new FormError("'$elname' is unknown", __FILE__, __LINE__);
return "";
}
if (isset($this->radio_elements[$elname]))
return "radio";
- $el = $this->elements[$elname];
- return $el->getType();
+ return $this->elements[$elname]->getType();
} // end func getType()
/**
* Return the current value of an element.
- * Use the function within your custom validation functions
+ *
+ * Use the function within your custom validation functions.
+ *
* <email protected> string $name element name
* <email protected> mixed $value
- * <email protected> FormNoSuchElement
+ * <email protected> FormError
* <email protected> public
*/
function getValue($name) {
if (!$this->ElementExists($name)) {
- $this->exception = new FormNoSuchElement("'$name' is unknown", __FILE__, __LINE__);
+ $this->exceptions[] = new FormNoSuchElement("'$name' is unknown", __FILE__, __LINE__);
return "";
}
- if (!isset($this->radio_elements[$name])) {
- $el = $this->elements[$name];
- return $el->getValue();
- }
+ if (!isset($this->radio_elements[$name]))
+ return $this->elements[$name]->getValue();
// Watch out: the meaning of $name changes!
// $name does now referr to the HTML/Javascript name of a group of
// elements, you can't adress one radio button by it's elname.
- $elements = $this->radio_elements[$name];
- reset($elements);
- while (list($elname, $v)=each($elements)) {
- $el = $this->elements[$elname];
- $value = $el->getValue();
- if (""!=$value)
- break;
- }
+ $value = "";
+ foreach ($this->radio_elements[$name] as $elname => $v)
+ if ($value = $this->elements[$elname]->getValue())
+ break;
return $value;
} // end func getValue
/**
- * Return and print an element
- * <email protected> string $name
- * <email protected> string $html
- * <email protected> public
+ * Return and print an element.
+ *
+ * <email protected> getElement()
*/
function showElement($name) {
$html = $this->getElement($name);
@@ -513,62 +480,59 @@
} // end func showElement
/**
- * Validate a form
+ * Validate a form.
+ *
* <email protected> mixed $vallist
* <email protected> array($error_msg, $error_flags)
* <email protected> public
*/
- function validate($vallist="") {
+ function validate($vallist = "") {
if (!is_array($vallist) && isset($this->elements[$vallist]))
$vallist = array($vallist);
- if (""==$vallist)
+
+ if ("" == $vallist)
$vallist = $this->getElementnames();
- $validators = $this->getCustomValidators($vallist);
- if (0!=count($validators)) {
- reset($validators);
- while (list($k, $validator)=each($validators))
- $this->${validator}();
- }
-
- reset($vallist);
- while (list($k, $name)=each($vallist)) {
+ foreach ($this->getCustomValidators($vallist) as $k => $validator)
+ $this->${validator}();
+
+ foreach ($vallist as $k => $name)
if (isset($this->elements[$name])) {
- $el = $this->elements[$name];
- list($ok, $message) = $el->validate();
+ list($ok, $message) = $this->elements[$name]->validate();
if (!$ok)
$this->setValidationError($name, $message);
}
- }
return $this->getValidationResult();
} // end func validate
/**
- * Sets the validation error message for an of an element
+ * Sets the validation error message for of an element.
+ *
* <email protected> string $name element name
* <email protected> string $message
* <email protected> boolean $ok
- * <email protected> FormNoSuchElement
+ * <email protected> FormError
* <email protected> getValidationResult(), validate()
*/
function setValidationError($name, $message) {
if (!$this->elementExists($name)) {
- $this->exception = new FormNoSuchElement("'$name' is unknown", __FILE__, __LINE__);
+ $this->exceptions[] = new FormError("'$name' is unknown", __FILE__, __LINE__);
return false;
}
- $this->validation_msg.= $message.$this->CR_HTML;
+ $this->validation_msg .= $message . $this->CR_HTML;
$this->validation_flags[$name] = $message;
return true;
} // end func setValidationsError
/**
- * Returns an array that holds the results of the last validation
- * <email protected> array($error_msg, $error_flags)
+ * Returns an array that holds the results of the last validation.
+ *
+ * <email protected> array ($error_msg, $error_flags)
* <email protected> private
* <email protected> setValidationError(), validate()
*/
@@ -578,7 +542,7 @@
/**
* Returns an array of all custom validation functions
- * <email protected> mixed $ellist L
+ * <email protected> mixed $ellist
* <email protected> array $validators $k => $custom_function
* <email protected> private
*/
@@ -586,191 +550,170 @@
if (!is_array($ellist) && isset($this->elements[$ellist]))
$ellist = array($ellist);
- if (""==$ellist)
+
+ if ("" == $ellist)
$ellist = $this->getElementnames();
$validators = array();
-
- reset($ellist);
- while (list($name, )=each($ellist))
+ foreach ($ellist as $name => $v)
if (isset($this->elements[$name])) {
- $el = $this->elements[$name];
- $validator = $el->getValidator();
- if ($validator) {
+ $validator = $this->elements[$name]->getValidator();
+ if ("" != $validator)
$validators[] = $validator;
- }
}
return $validators;
} // end func getCustomValidator
/**
- * Freeze an element, frozen elements are no longer drawn as form elements.
- * The user can't change the value of an frozen element
- * <email protected> mixed $flist = ""
- * <email protected> void
+ * Freeze an element, frozen elements are drawn in an non editable way.
+ *
+ * A user can't change the value of an frozen element.
+ *
+ * <email protected> mixed
* <email protected> public
*/
- function freeze($flist="") {
- if (""==$flist || !is_array($flist))
+ function freeze($flist = "") {
+ if ("" == $flist || !is_array($flist))
$flist = array($flist);
- if (0==count($flist))
+ if (0 == count($flist))
$flist == $this->elements;
- reset($flist);
- while (list($k, $name)=each($flist))
- if (isset($this->elements[$name])) {
- $el = $this->elements[$name];
- $el->freeze();
- $this->elements[$name] = $el;
- }
+ foreach ($flist as $k => $name)
+ if (isset($this->elements[$name]))
+ $this->elements[$name]->freeze();
} // end func freeze
/**
- * Thaw out an element
- * <email protected> mixed $flist = ""
+ * Thaw out an element.
+ *
+ * <email protected> mixed
* <email protected> void
* <email protected> public
* <email protected> freeze()
*/
- function unfreeze($flist="") {
- if (""==$flist || !is_array($flist))
+ function unfreeze($flist = "") {
+ if ("" == $flist || !is_array($flist))
$flist = array($flist);
- if (0==count($flist))
+ if (0 == count($flist))
$flist == $this->elements;
- reset($flist);
- while (list($k, $name)=each($flist))
- if (isset($this->elements[$name])) {
- $el = $this->elements[$name];
- $el->unfreeze();
- $this->elements[$name] = $el;
- }
+ foreach ($flist as $k => $name)
+ if (isset($this->elements[$name]))
+ $this->elements[$name]->unfreeze();
+
} // end func unfreeze
/**
+ * FIXME
* Adds JavaScript validation code to an element
* <email protected> string $name name of the element
* <email protected> string $code JavaScript code
* <email protected> bool $ok
- * <email protected> InvalidParameterException, FormNoSuchElement
+ * <email protected> FormError
* <email protected> public
*/
function addJS($name, $code) {
- if (""==$name || ""==$code) {
- $this->exception = new InvalidParameterException("No name and or no code given.", __FILE__, __LINE__);
+ if ("" == $name || "" == $code) {
+ $this->exceptions[] = new FormError("No name and or no code given.", __FILE__, __LINE__);
return false;
}
if (!$this->elementExists($name)) {
- $this->exception = new FormSoSuchElement("'$name' is unknown", __FILE__, __LINE__);
+ $this->exceptions[] = new FormError("'$name' is unknown", __FILE__, __LINE__);
return false;
}
-
- $el = $this->elements[$name];
- $ok = $el->addJS($code);
- $this->elements[$name] = $el;
- return $ok;
+ return $this->elements[$name]->addJS($code);
} // end func addJS
/**
- * Set JavaScript validation code
+ * Set JavaScript validation code.
+ *
* <email protected> string $name name of the element
* <email protected> string $code JavaScript code
* <email protected> bool $ok
* <email protected> public
+ * <email protected> FormError
*/
function setJS($name, $code) {
- if (""==$name || ""==$code) {
- $this->exception = new InvalidParameterException("No name and or no code given.", __FILE__, __LINE__);
+ if ("" == $name || "" == $code) {
+ $this->exceptions[] = new FormError("No name and or no code given.", __FILE__, __LINE__);
return false;
}
-
- ElementExists
- $el = $this->elements[$name];
- $ok = $el->setJS($code);
- $this->elements[$name] = $el;
+ if (!$this->elementExists($name)) {
+ $this->exceptions[] = new FormError("'$name' is unknown", __FILE__, __LINE__);
+ return false;
+ }
- return $ok;
+ return $this->elements[$name]->setJS($code);
} // end fun setJS
/**
- * Returns JavaScript validation code
+ * Returns JavaScript validation code.
+ *
* <email protected> string|array $names="" Name of one element, Array of elements or
* by default all elements
* <email protected> string $code JavaScript validation code
* <email protected> public
+ * <email protected> FormError
*/
- function getJS($names="") {
+ function getJS($names = "") {
- if (""==$this->js_name)
+ if ("" == $this->js_name)
return "";
- if (""==$names)
- $names = $this->getElements();
+ if ("" == $names)
+ $names = $this->element_names;
if (!is_array($names))
$names = array($names);
- if (0==count($names)) {
- $this->exception = new FormNoSuchElement("No elements given or no elements in form.", __FILE__, __LINE__);
+ if (0 == count($names)) {
+ $this->exceptions[] = new FormError("No elements given or no elements in form.", __FILE__, __LINE__);
return "";
}
$code = "";
- reset($names);
- while (list($k, $name)=each($names)) {
- if (isset($this->elements[$name])) {
- $el = $this->elements[$name];
- $code.= $el->getJS();
- $this->elements[$name] = $el;
- }
- }
+ foreach ($names as $k => $name)
+ if (isset($this->elements[$name]))
+ $code .= $this->elements[$name]->getJS();
return $code;
- } // end fun getJS
+ } // end func getJS
/**
- * Synonym of unfreeze - thaw out an element
- * <email protected> unfreeze(), freeze()
+ * <email protected> unfreeze
*/
- function thawout($flist="") {
+ function thawout($flist = "") {
return $this->unfreeze($flist);
- }
+ } // end func thawout
/**
- * Returns an array of all elements
+ * Returns an array of all elements.
+ *
* <email protected> array $elements[ name ] = name
* <email protected> public
*/
function getElements() {
- if (0==count($this->elements))
- return array();
-
- $elements = array();
-
- reset($this->elements);
- while (list($name, $data)=each($this->elements))
- $elements[$name] = $name;
-
- return $elements;
+ return $this->element_names;
} // end func getElements
+ /**
+ * FIXME
+ */
function getJSHead() {
- if (""==$this->js_name)
+ if ("" == $this->js_name)
return "";
- $js_code = "";
-
- $js_code.= sprintf('<script language="JavaScript1.2"><!--//%s',
+ $js_code = sprintf('<script language="JavaScript1.2"><!--//%s',
$this->CR_JS
);
- $js_code.= sprintf('function %s_Validator(f, onchange) {
+ $js_code .= sprintf('function %s_Validator(f, onchange) {
error_flags = new Array(%d);
error_flagtofield = new Array(%d);
error_msg = "";
@@ -785,11 +728,12 @@
return $this->clearCode($js_code);
} // end func getJSHead
+ /**
+ * FIXME
+ */
function getJSFoot() {
-
- $js_code = "";
- $js_code.= sprintf('
+ $js_code = sprintf('
if (""==onchange && err_id>0) {
%s_Complain(error_flags, error_flagtofield, error_msg, f, err_id);
return false;
@@ -846,18 +790,20 @@
} // end func getJSFoot
/**
- * Return an array of all options of a combo list
+ * Return an array of all options of a combo list.
+ *
* Comboboxes expand their option list. Take care that you save
* the expanded option list so that you can reload the new
- * option list after the form was submittet
+ * option list after the form was submittet.
+ *
* <email protected> mixed $ellist String with the name of one element or a list of elements.
* <email protected> array $options
- * <email protected> InvalidParameterException
+ * <email protected> FormError
* <email protected> public
*/
function getOptions($ellist) {
- if (""==$ellist) {
- $this->exception = new InvalidParameterException("No elements specified.", __FILE__, __LINE__);
+ if ("" == $ellist) {
+ $this->exceptions[] = new FormError("No elements specified.", __FILE__, __LINE__);
return array();
}
@@ -865,38 +811,31 @@
$ellist = array($ellist);
$options = array();
+ foreach ($ellist as $k => $name)
+ if (isset($this->elements[$name]))
+ $options[$name] = $this->elements[$name]->getOptions();
- reset($ellist);
- while (list($k, $name)=each($ellist))
- if (isset($this->elements[$name])) {
- $el = $this->elements[$name];
- $options[$name] = $el->getOptions();
- }
-
return $options;
} // end func getOptions
/*
- * Sets the options of a combobox
+ * Sets the options of a combobox.
+ *
* <email protected> string|array $ellist
* <email protected> bool $ok
- * <email protected> InvalidParameterException
+ * <email protected> FormError
* <email protected> public
* <email protected> getOptions()
*/
function setOptions($ellist) {
if (!is_array($ellist)) {
- $this->exception = new InvalidParameterException("No elements specified.", __FILE__, __LINE_);
+ $this->exceptions[] = new FormError("No elements specified.", __FILE__, __LINE_);
return false;
}
- reset($ellist);
- while (list($name, $options)=each($ellist))
- if (isset($this->elements[$name])) {
- $el = $this->elements[$name];
- $el->setOptions($options);
- $this->elements[$name] = $el;
- }
+ foreach ($ellist as $name => $options)
+ if (isset($this->elements[$name]))
+ $this->elements[$name]->setOptions($options);
return true;
} // end func setOptions
Index: php-lib/php/form/form_baseobject.inc
diff -u php-lib/php/form/form_baseobject.inc:1.2 php-lib/php/form/form_baseobject.inc:1.3
--- php-lib/php/form/form_baseobject.inc:1.2 Thu Jun 22 11:13:00 2000
+++ php-lib/php/form/form_baseobject.inc Mon Dec 11 20:17:49 2000
@@ -2,12 +2,14 @@
/**
* Superclass of a form object
*
-* <email protected> Ulf Wendel <ulf <email protected>>
+* <email protected> Ulf Wendel <ulf.wendel <email protected>>
+* <email protected> Form
+* <email protected> $Id: form_baseobject.inc,v 1.3 2000/12/11 19:17:49 uw Exp $
*/
class form_baseobject extends form_commonobject {
/**
- * Some default values
+ * Some default values
* <email protected> array $defaults
* <email protected> defaults
*/
@@ -30,7 +32,6 @@
"cssid" => "",
"cssclass" => "",
"cssstyle" => ""
-
&nb

