]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Implemented sticky forms.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 11 Mar 2010 19:14:32 +0000 (19:14 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 11 Mar 2010 19:14:32 +0000 (19:14 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@5368 36083f99-b078-4883-b0ff-0f9b5a30f544

16 files changed:
CHANGES.txt
engine/lib/elgglib.php
mod/tinymce/views/default/input/longtext.php
views/default/input/access.php
views/default/input/calendar.php
views/default/input/checkboxes.php
views/default/input/email.php
views/default/input/hidden.php
views/default/input/longtext.php
views/default/input/plaintext.php
views/default/input/pulldown.php
views/default/input/radio.php
views/default/input/tags.php
views/default/input/text.php
views/default/input/url.php
views/default/input/userpicker.php

index d4f5507dc7a5749a17257915bdf6ab95c8360a1b..3d64def69fae342d2d410363650116880540f5cb 100644 (file)
@@ -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().
 
 
 
index fd270bc1d4e48818c3b369fde0fd10e6d3406546..ac46df07822170cde82af4905bb8bc6706d08531 100644 (file)
@@ -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
  *
index 2907e1322e2d88830fb24da9dfcab0782dac6137..1ab7df1ff4caa883259de6c7b71331d71e9a6838 100644 (file)
@@ -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) {
-       
+
 ?>
 <!-- include tinymce -->
 <script language="javascript" type="text/javascript" src="<?php echo $vars['url']; ?>mod/tinymce/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
 <!-- intialise tinymce, you can find other configurations here http://wiki.moxiecode.com/examples/tinymce/installation_example_01.php -->
 <script language="javascript" type="text/javascript">
-   tinyMCE.init({
+tinyMCE.init({
        mode : "textareas",
        theme : "advanced",
        plugins : "safari,spellchecker,autosave,fullscreen,preview,paste",
        theme_advanced_path : true,
        extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|style],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
        setup : function(ed) {
-        // Add a custom button
-        //ed.addButton('more', {
-        //    title : 'more',
-        //    image : '<?php echo $vars['url']; ?>mod/tinymce/graphics/more.gif',
-        //    onclick : function() {
-        //        ed.selection.setContent('{{more}}');
-        //    }
-        //});
-  
-        //show the number of words
+               // Add a custom button
+               //ed.addButton('more', {
+               //    title : 'more',
+               //    image : '<?php echo $vars['url']; ?>mod/tinymce/graphics/more.gif',
+               //    onclick : function() {
+               //        ed.selection.setContent('{{more}}');
+               //    }
+               //});
+
+               //show the number of words
                ed.onLoadContent.add(function(ed, o) {
                var strip = (tinyMCE.activeEditor.getContent()).replace(/(&lt;([^&gt;]+)&gt;)/ig,"");
                var text = " Word count:" + strip.split(' ').length;
                tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + '_path_row'), text);
                });
-                
+
                ed.onKeyUp.add(function(ed, e) {
                var strip = (tinyMCE.activeEditor.getContent()).replace(/(&lt;([^&gt;]+)&gt;)/ig,"");
                var text = " Word count:" + strip.split(' ').length;
                tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + '_path_row'), text);
                });
-    }
+       }
 });
 function toggleEditor(id) {
 if (!tinyMCE.get(id))
@@ -82,7 +86,7 @@ else
 ?>
 
 <!-- show the textarea -->
-<textarea class="input_textarea" name="<?php echo $vars['internalname']; ?>" <?php echo $vars['js']; ?>><?php echo htmlentities($vars['value'], null, 'UTF-8'); ?></textarea> 
+<textarea class="input_textarea" name="<?php echo $vars['internalname']; ?>" <?php echo $vars['js']; ?>><?php echo htmlentities($vars['value'], null, 'UTF-8'); ?></textarea>
 <div class="toggle_editor_container"><a class="toggle_editor" href="javascript:toggleEditor('<?php echo $vars['internalname']; ?>');"><?php echo elgg_echo('tinymce:remove'); ?></a></div>
 
 <script type="text/javascript">
index e93b47cd1fb204278fafb5854054cd42e9b8b1d6..2515180ce5fec2db0e0e4973572ff3cc09c9a98e 100644 (file)
@@ -30,6 +30,9 @@ if (!array_key_exists('value', $vars) || $vars['value'] == ACCESS_DEFAULT) {
        $vars['value'] = get_default_access();
 }
 
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
 
 if ((!isset($vars['options'])) || (!is_array($vars['options']))) {
        $vars['options'] = array();
index 12cbf95ecf68ed370b4fcb3a4ea9d030eb9a7268..09c29753a0c8b156ffcf7b736477f2d806517bb6 100644 (file)
@@ -26,6 +26,10 @@ END;
 $strippedname = sanitise_string($vars['internalname']);
 $js = "cal" . $strippedname;
 
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
 if ($vars['value'] > 86400) {
        $val = date("F j, Y",$vars['value']);
 } else {
index 60674cb3c7b8c3ba0a044362538c1e9037c93c2a..fa7c0c34cb6d12f3c401cb92037570090369bfd5 100644 (file)
@@ -20,6 +20,10 @@ if (!$class) {
        $class = "input_checkboxes";
 }
 
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
 foreach($vars['options'] as $label => $option) {
        //if (!in_array($option,$vars['value'])) {
        if (is_array($vars['value'])) {
index 62a4ec993703302f24d02af12d57c3a6e7bc0c75..f8df87dd4d3eed03ed3f471fe5e6e52982b316a8 100644 (file)
@@ -20,6 +20,11 @@ $class = $vars['class'];
 if (!$class) {
        $class = "input_text";
 }
+
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
 ?>
 
 <input type="text" <?php echo $vars['js']; ?> name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?>value="<?php echo htmlentities($vars['value'], ENT_QUOTES, 'UTF-8'); ?>" class="<?php echo $class; ?>"/>
\ No newline at end of file
index e9577936786a576349a1717e9685831b288d0ba0..2abf4faf5c25631cd34a13ff88e4d1cf2606517c 100644 (file)
  * @uses $vars['internalname'] The name of the input field
  *
  */
+
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
 ?>
 <input type="hidden" <?php echo $vars['js']; ?> name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> value="<?php echo htmlentities($vars['value'], ENT_QUOTES, 'UTF-8'); ?>" />
\ No newline at end of file
index 328eb8f782f295387c84e8f8cdb3d8c8ab304b0d..e1bc235e3e9a9c6084472c82be3d1c1f7c7652c8 100644 (file)
@@ -26,6 +26,10 @@ if (isset($vars['disabled'])) {
        $disabled = $vars['disabled'];
 }
 
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
 $value = '';
 if (isset($vars['value'])) {
        $value = $vars['value'];
index 22171a7a73cc366a02e43a614d871b580d70beb0..dd11789457087d764cb847198843237803ffedbe 100644 (file)
@@ -19,6 +19,10 @@ if (!$class) {
        $class = "input_textarea";
 }
 
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
 ?>
 
 <textarea class="<?php echo $class; ?>" name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> <?php if ($vars['disabled']) echo ' disabled="yes" '; ?> <?php echo $vars['js']; ?>><?php echo htmlentities($vars['value'], ENT_QUOTES, 'UTF-8'); ?></textarea>
\ No newline at end of file
index 59c8a7adc70eb4ffdadfc18a8e84c2781172644f..b24d92b381e4cf628d4f614b3d847cbb0a912b67 100644 (file)
@@ -21,6 +21,10 @@ if (!$class) {
        $class = "input_pulldown";
 }
 
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
 ?>
 
 <select name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> <?php echo $vars['js']; ?> <?php if ($vars['disabled']) echo ' disabled="yes" '; ?> class="<?php echo $class; ?>">
index 8304d073708fe9f46d22db0874c1ceec9062814a..fe7335b8a6c6c7577e22f1fcc377debf3ea396d8 100644 (file)
@@ -20,6 +20,10 @@ if (!$class) {
        $class = "input_radio";
 }
 
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
 foreach($vars['options'] as $label => $option) {
        if (strtolower($option) != strtolower($vars['value'])) {
                $selected = "";
index 3592edb101a317f24e8d3bce0a7912321ba10802..1c71cb0e02a679716a5bf36fb144704d93a48a6f 100644 (file)
@@ -29,6 +29,10 @@ if (isset($vars['disabled'])) {
        $disabled = $vars['disabled'];
 }
 
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
 $tags = "";
 if (!empty($vars['value'])) {
        if (is_array($vars['value'])) {
index aa6e571b6de7e1a64104727acad52849a6f8f7f3..a77956985f0c8529011baf7f55f93b0830b45e69 100644 (file)
@@ -29,6 +29,12 @@ if (isset($vars['disabled'])) {
        $disabled = $vars['disabled'];
 }
 
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
+$value = htmlentities($vars['value'], ENT_QUOTES, 'UTF-8');
+
 ?>
 
-<input type="text" <?php if ($disabled) echo ' disabled="yes" '; ?> <?php echo $vars['js']; ?> name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> value="<?php echo htmlentities($vars['value'], ENT_QUOTES, 'UTF-8'); ?>" class="<?php echo $class ?>"/>
\ No newline at end of file
+<input type="text" <?php if ($disabled) echo ' disabled="yes" '; ?> <?php echo $vars['js']; ?> name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> value="<?php echo $value; ?>" class="<?php echo $class ?>"/>
\ No newline at end of file
index 571754c778639aa74db83a5604512a30439b44eb..0b9e124c62a0e30850a918635e929bb38f3d0430 100644 (file)
@@ -18,6 +18,11 @@ $class = $vars['class'];
 if (!$class) {
        $class = "input_url";
 }
+
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
 ?>
 
 <input type="text" <?php if ($vars['disabled']) echo ' disabled="yes" '; ?> <?php echo $vars['js']; ?> name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['internalid'])) echo "id=\"{$vars['internalid']}\""; ?> value="<?php echo htmlentities($vars['value'], ENT_QUOTES, 'UTF-8'); ?>" class="<?php echo $class; ?>"/>
\ No newline at end of file
index 742554dbd3bc87c2b5f6d4aec12430b9049def31..18f3085c2a950b3fcdbe0a27ef667419a00e0874 100644 (file)
 
 global $user_picker_js_sent;
 
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+       $vars['value'] = elgg_get_sticky_value($vars['internalname']);
+}
+
 if (!$user_picker_js_sent) {
 ?>
 <!-- User picker JS -->