Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
StickyForms.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Forms;
3 
13 class StickyForms {
14 
25  public function makeStickyForm($form_name) {
26  $this->clearStickyForm($form_name);
27 
28  $banned_keys = [];
29  // TODO make $banned_keys an argument
30  if (in_array($form_name, ['register', 'useradd', 'usersettings'])) {
31  $banned_keys = ['password', 'password2'];
32  }
33 
34  $session = _elgg_services()->session;
35  $data = $session->get('sticky_forms', array());
36  $req = _elgg_services()->request;
37 
38  // will go through XSS filtering in elgg_get_sticky_value()
39  $vars = array_merge($req->query->all(), $req->request->all());
40  foreach ($banned_keys as $key) {
41  unset($vars[$key]);
42  }
43  $data[$form_name] = $vars;
44 
45  $session->set('sticky_forms', $data);
46  }
47 
59  function clearStickyForm($form_name) {
60  $session = _elgg_services()->session;
61  $data = $session->get('sticky_forms', array());
62  unset($data[$form_name]);
63  $session->set('sticky_forms', $data);
64  }
65 
73  function isStickyForm($form_name) {
74  $session = _elgg_services()->session;
75  $data = $session->get('sticky_forms', array());
76  return isset($data[$form_name]);
77  }
78 
91  function getStickyValue($form_name, $variable = '', $default = null, $filter_result = true) {
92  $session = _elgg_services()->session;
93  $data = $session->get('sticky_forms', array());
94  if (isset($data[$form_name][$variable])) {
95  $value = $data[$form_name][$variable];
96  if ($filter_result) {
97  // XSS filter result
99  }
100  return $value;
101  }
102  return $default;
103  }
104 
113  function getStickyValues($form_name, $filter_result = true) {
114  $session = _elgg_services()->session;
115  $data = $session->get('sticky_forms', array());
116  if (!isset($data[$form_name])) {
117  return array();
118  }
119 
120  $values = $data[$form_name];
121  if ($filter_result) {
122  foreach ($values as $key => $value) {
123  // XSS filter result
124  $values[$key] = filter_tags($value);
125  }
126  }
127  return $values;
128  }
129 
138  function clearStickyValue($form_name, $variable) {
139  $session = _elgg_services()->session;
140  $data = $session->get('sticky_forms', array());
141  unset($data[$form_name][$variable]);
142  $session->set('sticky_forms', $data);
143  }
144 }
getStickyValues($form_name, $filter_result=true)
Get all submission data cached for a form.
$data
Definition: opendd.php:13
$value
Definition: longtext.php:26
getStickyValue($form_name, $variable= '', $default=null, $filter_result=true)
Get a specific value from cached form submission data.
Definition: StickyForms.php:91
$default
Definition: checkbox.php:35
filter_tags($var)
Filter tags from a given string based on registered hooks.
Definition: input.php:53
isStickyForm($form_name)
Does form submission data exist for this form?
Definition: StickyForms.php:73
$vars['entity']
clearStickyValue($form_name, $variable)
Remove one value of form submission data from the session.
$key
Definition: summary.php:34
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
makeStickyForm($form_name)
Save form submission data (all GET and POST vars) into a session cache.
Definition: StickyForms.php:25
$session
Definition: login.php:9
clearStickyForm($form_name)
Remove form submission data from the session.
Definition: StickyForms.php:59