aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-03-11 19:14:32 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-03-11 19:14:32 +0000
commitd3334ef71b8e71e0db6c463436555f406941d5c9 (patch)
treecd4109bcc0d7abf2528cf5940e6c132c3e98b01a /engine/lib
parent982d56d370ba021e17a6e8548cdeb26345a89380 (diff)
downloadelgg-d3334ef71b8e71e0db6c463436555f406941d5c9.tar.gz
elgg-d3334ef71b8e71e0db6c463436555f406941d5c9.tar.bz2
Implemented sticky forms.
git-svn-id: http://code.elgg.org/elgg/trunk@5368 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/elgglib.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index fd270bc1d..ac46df078 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -2710,6 +2710,80 @@ function elgg_get_breadcrumbs() {
/**
+ * Sticky forms
+ */
+
+/**
+ * Load all the REQUEST variables into the sticky form cache
+ *
+ * Call this from an action when you want all your submitted variables
+ * available if the submission fails validation and is sent back to the form
+ */
+function elgg_make_sticky_form() {
+ elgg_clear_sticky_form();
+
+ $_SESSION['sticky_form'] = array();
+
+ foreach($_REQUEST as $key => $var) {
+ // will go through XSS filtering on the get function
+ $_SESSION['sticky_form'][$key] = $var;
+ }
+}
+
+
+/**
+ * Clear the sticky form cache
+ *
+ * Call this if validation is successful in the action handler or
+ * when they sticky values have been used to repopulate the form
+ * after a validation error.
+ */
+function elgg_clear_sticky_form() {
+ unset($_SESSION['sticky_form']);
+}
+
+/**
+ * Has this form been made sticky
+ *
+ * @return boolean
+ */
+function elgg_is_sticky_form() {
+ return isset($_SESSION['sticky_form']);
+}
+
+/**
+ * Get a specific stick variable
+ *
+ * @param string $variable The name of the variable
+ * @param mixed $default Default value if the variable does not exist in sticky cache
+ * @param boolean $filter_result Filter for bad input if true
+ * @return mixed
+ *
+ * @todo should this filter the default value?
+ */
+function elgg_get_sticky_value($variable, $default = "", $filter_result = true) {
+ if (isset($_SESSION['sticky_form'][$variable])) {
+ $value = $_SESSION['sticky_form'][$variable];
+ if ($filter_result) {
+ // XSS filter result
+ $value = filter_tags($value);
+ }
+ return $value;
+ }
+ return $default;
+}
+
+/**
+ * Clear a specific sticky variable
+ *
+ * @param string $variable The name of the variable to clear
+ */
+function elgg_clear_sticky_value($variable) {
+ unset($_SESSION['sticky_form'][$variable]);
+}
+
+
+/**
* Returns the PHP INI setting in bytes
*
* @param str $setting