aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--CHANGES.txt8
-rw-r--r--engine/lib/elgglib.php74
-rw-r--r--mod/tinymce/views/default/input/longtext.php44
-rw-r--r--views/default/input/access.php3
-rw-r--r--views/default/input/calendar.php4
-rw-r--r--views/default/input/checkboxes.php4
-rw-r--r--views/default/input/email.php5
-rw-r--r--views/default/input/hidden.php5
-rw-r--r--views/default/input/longtext.php4
-rw-r--r--views/default/input/plaintext.php4
-rw-r--r--views/default/input/pulldown.php4
-rw-r--r--views/default/input/radio.php4
-rw-r--r--views/default/input/tags.php4
-rw-r--r--views/default/input/text.php8
-rw-r--r--views/default/input/url.php5
-rw-r--r--views/default/input/userpicker.php4
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
@@ -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
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) {
-
+
?>
<!-- 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",
@@ -44,28 +48,28 @@
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">
diff --git a/views/default/input/access.php b/views/default/input/access.php
index e93b47cd1..2515180ce 100644
--- a/views/default/input/access.php
+++ b/views/default/input/access.php
@@ -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();
diff --git a/views/default/input/calendar.php b/views/default/input/calendar.php
index 12cbf95ec..09c29753a 100644
--- a/views/default/input/calendar.php
+++ b/views/default/input/calendar.php
@@ -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 {
diff --git a/views/default/input/checkboxes.php b/views/default/input/checkboxes.php
index 60674cb3c..fa7c0c34c 100644
--- a/views/default/input/checkboxes.php
+++ b/views/default/input/checkboxes.php
@@ -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'])) {
diff --git a/views/default/input/email.php b/views/default/input/email.php
index 62a4ec993..f8df87dd4 100644
--- a/views/default/input/email.php
+++ b/views/default/input/email.php
@@ -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
diff --git a/views/default/input/hidden.php b/views/default/input/hidden.php
index e95779367..2abf4faf5 100644
--- a/views/default/input/hidden.php
+++ b/views/default/input/hidden.php
@@ -14,5 +14,10 @@
* @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
diff --git a/views/default/input/longtext.php b/views/default/input/longtext.php
index 328eb8f78..e1bc235e3 100644
--- a/views/default/input/longtext.php
+++ b/views/default/input/longtext.php
@@ -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'];
diff --git a/views/default/input/plaintext.php b/views/default/input/plaintext.php
index 22171a7a7..dd1178945 100644
--- a/views/default/input/plaintext.php
+++ b/views/default/input/plaintext.php
@@ -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
diff --git a/views/default/input/pulldown.php b/views/default/input/pulldown.php
index 59c8a7adc..b24d92b38 100644
--- a/views/default/input/pulldown.php
+++ b/views/default/input/pulldown.php
@@ -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; ?>">
diff --git a/views/default/input/radio.php b/views/default/input/radio.php
index 8304d0737..fe7335b8a 100644
--- a/views/default/input/radio.php
+++ b/views/default/input/radio.php
@@ -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 = "";
diff --git a/views/default/input/tags.php b/views/default/input/tags.php
index 3592edb10..1c71cb0e0 100644
--- a/views/default/input/tags.php
+++ b/views/default/input/tags.php
@@ -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'])) {
diff --git a/views/default/input/text.php b/views/default/input/text.php
index aa6e571b6..a77956985 100644
--- a/views/default/input/text.php
+++ b/views/default/input/text.php
@@ -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
diff --git a/views/default/input/url.php b/views/default/input/url.php
index 571754c77..0b9e124c6 100644
--- a/views/default/input/url.php
+++ b/views/default/input/url.php
@@ -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
diff --git a/views/default/input/userpicker.php b/views/default/input/userpicker.php
index 742554dbd..18f3085c2 100644
--- a/views/default/input/userpicker.php
+++ b/views/default/input/userpicker.php
@@ -22,6 +22,10 @@
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 -->