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 --- CHANGES.txt | 8 ++- engine/lib/elgglib.php | 74 ++++++++++++++++++++++++++++ mod/tinymce/views/default/input/longtext.php | 44 +++++++++-------- views/default/input/access.php | 3 ++ views/default/input/calendar.php | 4 ++ views/default/input/checkboxes.php | 4 ++ views/default/input/email.php | 5 ++ views/default/input/hidden.php | 5 ++ views/default/input/longtext.php | 4 ++ views/default/input/plaintext.php | 4 ++ views/default/input/pulldown.php | 4 ++ views/default/input/radio.php | 4 ++ views/default/input/tags.php | 4 ++ views/default/input/text.php | 8 ++- views/default/input/url.php | 5 ++ views/default/input/userpicker.php | 4 ++ 16 files changed, 161 insertions(+), 23 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d4f5507dc..3d64def69 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,12 +1,16 @@ Version 1.8.0 (??? from http://code.elgg.org/branches/1.8/) - API changes: + User-visible changes: + + Generic API changes: * Added elgg_instanceof(). - UI/UX + UI/UX API changes: * Added elgg_push_breadcrumb(), elgg_pop_breadcrumb(), and elgg_get_breadcrumbs(). * Added navigation/breadcrumbs. + * Added sticky form support with elgg_make_sticky_form(), + elgg_clear_sticky_form(), elgg_is_sticky_form(), and elgg_get_sticky_value(). 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 * diff --git a/mod/tinymce/views/default/input/longtext.php b/mod/tinymce/views/default/input/longtext.php index 2907e1322..1ab7df1ff 100644 --- a/mod/tinymce/views/default/input/longtext.php +++ b/mod/tinymce/views/default/input/longtext.php @@ -3,33 +3,37 @@ /** * Elgg long text input with the tinymce text editor intacts * Displays a long text input field - * + * * @package ElggTinyMCE * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @author Curverider Ltd * @copyright Curverider Ltd 2008-2010 * @link http://elgg.org/ - * + * * @uses $vars['value'] The current value, if any * @uses $vars['js'] Any Javascript to enter into the input tag * @uses $vars['internalname'] The name of the input field - * + * */ global $tinymce_js_loaded; - + + if (!isset($vars['value']) || $vars['value'] === FALSE) { + $vars['value'] = elgg_get_sticky_value($vars['internalname']); + } + $input = rand(0,9999); - + if (!isset($tinymce_js_loaded)) $tinymce_js_loaded = false; if (!$tinymce_js_loaded) { - + ?>