Date: 04/12/00
- Next message: Ulf Wendel: "Re: [PHPLIB-DEV] cvs commit"
- Previous message: kir: "[PHPLIB-DEV] cvs commit"
- Next in thread: Ulf Wendel: "Re: [PHPLIB-DEV] cvs commit"
- Reply: Ulf Wendel: "Re: [PHPLIB-DEV] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: uw
Date: Wed Apr 12 21:22:50 2000
Added files:
php-lib/php/new_assistant.inc
php-lib/php/new_my_assistant.inc
Modified files:
php-lib/php/new_form.inc
php-lib/php/new_form_elements.inc
php-lib/php/new_form_to_template.inc
Log message:
Assistant guides a user through several forms. When one form is completed
the user is allowed to select the next.
Index: php-lib/php/new_form.inc
diff -u php-lib/php/new_form.inc:1.1 php-lib/php/new_form.inc:1.2
--- php-lib/php/new_form.inc:1.1 Sat Apr 8 16:10:56 2000
+++ php-lib/php/new_form.inc Wed Apr 12 21:22:18 2000
@@ -124,6 +124,95 @@
var $cr_js = "\n";
/**
+ * Method (POST|GET) used
+ * <email protected> string $method
+ * <email protected> private
+ * <email protected> Start(), autoloadValues()
+ */
+ var $method="POST";
+
+ /**
+ * Returns an array with elname => value pairs, that can be used
+ * to be stored in a session. new_assistant needs this
+ * <email protected> array $session_hash
+ * <email protected> public
+ */
+ function getSessionHash() {
+ if (0==count($this->elements)) {
+ $this->setError(43, "new_form -> getSessionHash(), no elements in form");
+ return array();
+ }
+
+ $data = array();
+ reset($this->elements);
+ while (list($elname, $value)=each($this->elements))
+ $data[$elname] = $this->getValue($elname);
+
+ return $data;
+ } // end func getSessionHash
+
+ /**
+ * set 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;
+ } // end func setMethod
+
+ /**
+ * Loads the form with HTTP_[POST|GET]_VARS
+ * <email protected> array $ellist
+ * <email protected> boolean $ok
+ * <email protected> public
+ */
+ function autoloadValues($ellist="") {
+ if (""==$ellist)
+ $ellist = $this->getElementnames();
+ if (!is_array($ellist))
+ $ellist = array($ellist);
+ if (!is_array($ellist) || 0==count($ellist)) {
+ $this->setError(43, "new_form -> autoloadValues(), no elements in form");
+ return false;
+ }
+
+ $data = ("POST" == $this->method) ? $GLOBALS["HTTP_POST_VARS"] : $GLOBALS["HTTP_GET_VARS"];
+ if (!is_array($data) || 0==count($data)) {
+ $this->setError(44, sprintf("new_form -> autoloadValues(), warning: no HTTP_%s_VARS", $this->method) );
+ return true;
+ }
+
+ reset($ellist);
+ while (list($k, $name)=each($ellist)) {
+ if (!isset($data[$name]))
+ continue;
+
+ if (isset($this->elements[$name])) {
+
+ $el = $this->elements[$name];
+ $el->setValue($data[$name]);
+ $this->elements[$name] = $el;
+
+ } 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($data[$name]);
+ $this->elements[$elname] = $el;
+ }
+
+ }
+
+ } // end while
+
+ return true;
+ } // end func autoloadValues
+ /**
* Sets the values of elements
* You'll need it to reload submitted values
* <email protected> array $values elementname => value
@@ -141,13 +230,13 @@
reset($values);
while (list($name, $value)=each($values))
if (isset($this->elements[$name])) {
-
+
$el = $this->elements[$name];
$el->setValue($value);
$this->elements[$name] = $el;
} else if (isset($this->radio_elements[$name])) {
-
+
$elements = $this->radio_elements[$name];
reset($elements);
while (list($elname, $v)=each($elements)) {
@@ -272,13 +361,13 @@
(""==$action) ? $PHP_SELF : $action,
(""==$target) ? "_self" : $target
);
-
+
+ $html.= sprintf('method="%s" ', ("GET"==strtoupper($method)) ? "GET" : "POST" );
if ($this->flag_file) {
$html.= 'enctype="multipart/form-data" ';
$method = "POST";
}
-
- $html.= sprintf('method="%s" ', ("GET"==strtoupper($method)) ? "GET" : "POST" );
+ $this->setMethod($method);
if (""!=$js_name) {
$this->js_name = $js_name;
@@ -494,6 +583,22 @@
} // end func getElement
/**
+ * Return the type of an element
+ * <email protected> string $elname
+ * <email protected> public
+ */
+ function getType($elname) {
+ if (!$this->ElementExists("getType", $elname, array(40, 41)))
+ return "";
+
+ if (isset($this->radio_elements[$elname]))
+ return "radio";
+
+ $el = $this->elements[$elname];
+ return $el->getType();
+ } // end func getType()
+
+ /**
* Return the current value of an element.
* Use the function within your custom validation functions
* <email protected> string $name element name
@@ -659,6 +764,7 @@
* <email protected> string $name element name
* <email protected> boolean $ok true => don't care, false => save error
* <email protected> string $message
+ * <email protected> private
* <email protected> getValidationResult(), validate()
*/
function setValidationError($name, $ok, $message) {
Index: php-lib/php/new_form_elements.inc
diff -u php-lib/php/new_form_elements.inc:1.1 php-lib/php/new_form_elements.inc:1.2
--- php-lib/php/new_form_elements.inc:1.1 Sat Apr 8 16:10:56 2000
+++ php-lib/php/new_form_elements.inc Wed Apr 12 21:22:18 2000
@@ -25,6 +25,8 @@
$this->flag_file = true;
if ("radio"==$element_data["type"])
$this->flag_radio = true;
+ if ("submit"==$element_data["type"])
+ $this->flag_button = true;
if (isset($element_data["hidden"]))
$this->flag_hidden = true;
@@ -152,6 +154,14 @@
*/
var $flag_radio = false;
+ /**
+ * Is this a button (reset/image/submit)
+ * <email protected> boolean $flag_button = false
+ * <email protected> private
+ * <email protected> isButton()
+ */
+ var $flag_button = false;
+
var $flag_showerror = false;
var $flag_haltonerror = false;
@@ -205,6 +215,13 @@
return $this->value;
} // end func getValue()
+ /**
+ * Return the type of this element
+ * <email protected> string $type
+ */
+ function getType() {
+ return (string)$this->type;
+ } // end func getType()
/**
* Returns the name of the custom validation function
* <email protected> string $custom_validator
@@ -212,7 +229,7 @@
* <email protected> setValidator()
*/
function getValidator() {
- return $this->validator;
+ return (string)$this->validator;
} // end func getValidator
/**
@@ -588,6 +605,10 @@
function isFile() {
return $this->flag_file;
}
+
+ function isButton() {
+ return $this->flag_button;
+ }
/**
* Reformate generated code
Index: php-lib/php/new_form_to_template.inc
diff -u php-lib/php/new_form_to_template.inc:1.1 php-lib/php/new_form_to_template.inc:1.2
--- php-lib/php/new_form_to_template.inc:1.1 Mon Apr 10 14:35:10 2000
+++ php-lib/php/new_form_to_template.inc Wed Apr 12 21:22:19 2000
@@ -149,6 +149,71 @@
var $cr_html = "\n";
/**
+ * Return a hash of form values
+ * <email protected> array $session_hash
+ * <email protected> public
+ * <email protected> restoreSessionHash()
+ */
+ function getSessionHash() {
+ if (0==count($this->elements)) {
+ $this->setError(30, "newform -> getSessionHash(), no elements in template");
+ return array();
+ }
+
+ $session_hash = array();
+
+ reset($this->elements);
+ while (list($k, $data)=each($this->elements))
+ if ("form"==$data["type"])
+ $session_hash[$data["name"]] = $this->form->getValue($data["name"]);
+
+ return $session_hash;
+ } // end func getSessionHash()
+
+ /**
+ * Restores a session hash
+ * <email protected> array $session_hash
+ * <email protected> boolean $ok
+ * <email protected> getSessionHash()
+ */
+ function restoreSessionHash($session_hash) {
+ if (!is_array($session_hash) || 0==count($session_hash)) {
+ $this->setError(31, "newform -> restoreSessionHash(), warning: no data provided");
+ return false;
+ }
+ return $this->form->setValues($session_hash);
+ } // end func restoreSessionHash
+
+ /**
+ * Are there errors in this form?
+ * <email protected> boolean $ok
+ * <email protected> public
+ */
+ function isValid() {
+ list($msg, $flags)=$this->form->validate();
+
+ reset($this->elements);
+ while (list($k, $data)=each($this->elements))
+ if ("form"==$data["type"])
+ if (!isset($data["optional"]) && isset($flags[$data["name"]]) )
+ return false;
+
+ return true;
+ } // end func isValid
+
+ /**
+ * Set the method used in the form. Form needs it for autoloadValues().
+ * You set the method eighter by Start() or be setMethod()
+ * <email protected> $method = "POST"
+ * <email protected> public
+ */
+ function setMethod($method="POST") {
+ if ("POST"!=strtoupper($method))
+ $method = "GET";
+ $this->form->setMethod($method);
+ } // end func $method
+
+ /**
* Create a new instance of template
* <email protected> boolean $ok
* <email protected> private
@@ -579,7 +644,13 @@
$this->tpl->set_var( $replace );
- list($msg, $flags) = $this->form->validate();
+ $ellist = array();
+ reset($this->elements);
+ while (list($k, $data)=each($this->elements))
+ if ("form"==$data["type"])
+ $ellist[]=$data["name"];
+
+ list($msg, $flags) = $this->form->validate($ellist);
$counter = 0;
reset($this->elements);
-
PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in
the body, not the subject, of your message.
- Next message: Ulf Wendel: "Re: [PHPLIB-DEV] cvs commit"
- Previous message: kir: "[PHPLIB-DEV] cvs commit"
- Next in thread: Ulf Wendel: "Re: [PHPLIB-DEV] cvs commit"
- Reply: Ulf Wendel: "Re: [PHPLIB-DEV] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

