-
Notifications
You must be signed in to change notification settings - Fork 0
/
client settings source
51 lines (30 loc) · 1.75 KB
/
client settings source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
//Creates form open tag, target variable can be used to specify what page to go to on form submission (need to default this to the current resource ID)
print '<form action="'.$target.'" method="POST">';
//Checks if the submite button was pressed, if true it will execute
if (isset($_POST['submit'])) {
//Success Message to display
print "<p>Changes saved successfully.</p>";
//get MODX context settings and insert them into an array based on category variable in snippet call (can be left blank, need to make this a default setting)
$relatedSettings = $modx->getCollection('modContextSetting', array('area'=>$category));
//loop to set new values to each setting and save it
foreach ($relatedSettings as $Setting) {
if (isset($_POST[$Setting->get('key')])) {
$Setting->set('value', $_POST[$Setting->get('key')]);
$Setting->save();
};
};
//clear cache
$cm = $modx->getCacheManager();
$cm->refresh();
//Log form values, uncomment to debug
//$modx->log(modX::LOG_LEVEL_ERROR, '[My-Snippet] - POST:'.print_r($_POST, true) );
}
//if to render each setting from the category parameter
if (!isset($relatedSettings)) $relatedSettings = $modx->getCollection('modContextSetting', array('area'=>$category));
//loop to render each setting in an input field
foreach ( $relatedSettings as $Setting ) {
print '<label>'.$Setting->get('key').'</label><br/><input type="text" name="'.$Setting->get('key').'" value="'.$Setting->get('value').'"><br/>';
};
//creates the form submit button and closes the form tag (need to add templating via chunk for the whole snippet)
print "<input type='submit' value='Save' class='submit' name='submit'></form>";