So I'm making a custom snippet to make a page so my client can edit the context settings I put on his site, I know there's a plugin called ClientConfig by the awesome Mark Hamstra but the issue is I don't give my clients access to the manager they edit everything on the front end with NewsPublisher.
With that said I already got the context settings rendered on the page and the form submits the changes (Thanks Mark Hamstra) but it is not saving the changes, any help would be greatly appreciated, thanks.
Updated Code to reflect changes made
<?php
print '<form action="'.$target.'" method="POST">';
if (isset($_POST['submit'])) {
print "Form was successfully submitted.<br/>";
$relatedSettings = $modx->getCollection('modContextSetting', array('area'=>$category));
foreach ($relatedSettings as $Setting) {
if (isset($_POST[$Setting->get('key')])) {
$Setting->set('value', $_POST[$Setting->get('key')]);
$Setting->save();
//clear cache in MODx 2.1.x
$cacheRefreshOptions = array( 'system_settings' => array() );
$modx->cacheManager-> refresh($cacheRefreshOptions);
};
$modx->log(modX::LOG_LEVEL_ERROR, '[Show Settings] - set value:'.$_POST[$Setting->get('key')]);
$modx->log(modX::LOG_LEVEL_ERROR, '[My-Snippet] - POST:'.print_r($_POST, true) );
};
}
if (!isset($relatedSettings)) $relatedSettings = $modx->getCollection('modContextSetting', array('area'=>$category));
foreach ( $relatedSettings as $Setting ) {
print '<label>'.$Setting->get('key').'</label><br/><input type="text" name="'.$Setting->get('key').'" value="'.$Setting->get('value').'">';
};
print "<input type='submit' value='Save' class='alignright' name='submit'><div class='clearfix'></div>";
print '</form>';
What I get in the error logs is the following:
[2013-01-15 06:06:10] (ERROR @ /index.php) [Show Settings] - set value:
[2013-01-15 06:06:10] (ERROR @ /index.php) [My-Snippet] - POST:Array
(
[submit] => Save
)
I get one of these for each setting on the page.
[ed. note: benmarte last edited this post 11 years, 4 months ago.]