From d3334ef71b8e71e0db6c463436555f406941d5c9 Mon Sep 17 00:00:00 2001 From: brettp Date: Thu, 11 Mar 2010 19:14:32 +0000 Subject: Implemented sticky forms. git-svn-id: http://code.elgg.org/elgg/trunk@5368 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'engine/lib/elgglib.php') 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 @@ -2709,6 +2709,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 * -- cgit v1.2.3