Elgg  Version 3.0
StickyForms.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Forms;
4 
14 class StickyForms {
15 
26  public function makeStickyForm($form_name) {
27  $this->clearStickyForm($form_name);
28 
29  $banned_keys = [];
30  // TODO make $banned_keys an argument
31  if (in_array($form_name, ['register', 'useradd', 'usersettings'])) {
32  $banned_keys = ['password', 'password2'];
33  }
34 
35  $session = _elgg_services()->session;
36  $data = $session->get('sticky_forms', []);
37  $req = _elgg_services()->request;
38 
39  // will go through XSS filtering in elgg_get_sticky_value()
40  $vars = array_merge($req->query->all(), $req->request->all());
41  foreach ($banned_keys as $key) {
42  unset($vars[$key]);
43  }
44  $data[$form_name] = $vars;
45 
46  $session->set('sticky_forms', $data);
47  }
48 
60  public function clearStickyForm($form_name) {
61  $session = _elgg_services()->session;
62  $data = $session->get('sticky_forms', []);
63  unset($data[$form_name]);
64  $session->set('sticky_forms', $data);
65  }
66 
74  public function isStickyForm($form_name) {
75  $session = _elgg_services()->session;
76  $data = $session->get('sticky_forms', []);
77  return isset($data[$form_name]);
78  }
79 
92  public function getStickyValue($form_name, $variable = '', $default = null, $filter_result = true) {
93  $session = _elgg_services()->session;
94  $data = $session->get('sticky_forms', []);
95  if (isset($data[$form_name][$variable])) {
96  $value = $data[$form_name][$variable];
97  if ($filter_result) {
98  // XSS filter result
100  }
101  return $value;
102  }
103  return $default;
104  }
105 
114  public function getStickyValues($form_name, $filter_result = true) {
115  $session = _elgg_services()->session;
116  $data = $session->get('sticky_forms', []);
117  if (!isset($data[$form_name])) {
118  return [];
119  }
120 
121  $values = $data[$form_name];
122  if ($filter_result) {
123  foreach ($values as $key => $value) {
124  // XSS filter result
125  $values[$key] = filter_tags($value);
126  }
127  }
128  return $values;
129  }
130 
139  public function clearStickyValue($form_name, $variable) {
140  $session = _elgg_services()->session;
141  $data = $session->get('sticky_forms', []);
142  unset($data[$form_name][$variable]);
143  $session->set('sticky_forms', $data);
144  }
145 }
getStickyValues($form_name, $filter_result=true)
Get all submission data cached for a form.
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:57
getStickyValue($form_name, $variable= '', $default=null, $filter_result=true)
Get a specific value from cached form submission data.
Definition: StickyForms.php:92
filter_tags($var)
Filter tags from a given string based on registered hooks.
Definition: input.php:82
isStickyForm($form_name)
Does form submission data exist for this form?
Definition: StickyForms.php:74
clearStickyValue($form_name, $variable)
Remove one value of form submission data from the session.
$default
Definition: checkbox.php:35
makeStickyForm($form_name)
Save form submission data (all GET and POST vars) into a session cache.
Definition: StickyForms.php:26
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
$value
Definition: debugging.php:7
$vars['type']
Definition: save.php:11
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
clearStickyForm($form_name)
Remove form submission data from the session.
Definition: StickyForms.php:60