Previously, we covered how to Add Your Own Links to the SugarCRM Admin Option Page. This post will cover how to save configurations on that option page to the database using SugarCRM's Administration class.

Given this simplified form with no formatting yet applied:

<form name="ConfigureSettings" id="EditView" method="POST" >
<input type="hidden" name="module" value="abc_Module">
<input type="hidden" name="action" value=”SaveConfig”>
API URL: <input type="text" name="api_url" value="" size="35"/><br/>
<input type='submit' value='Save Configuration' />
</form>
view raw config.html hosted with ❤ by GitHub

Once the form is submitted we can process the form in our SaveConfig.php:

<?php
require_once('modules/Administration/Administration.php');
$administration = new Administration();
//do data validation, etc here
//....
//save the setting to the config table
$administration->saveSetting('abc_Module', 'api_url', $_REQUEST['api_url']);
view raw SaveConfig.php hosted with ❤ by GitHub

To retrieve that setting:

<?php
require_once('modules/Administration/Administration.php');
$administration = new Administration();
$administration->retrieveSettings();
$api_url = $administration->settings['abc_Module_api_url'];
view raw config.php hosted with ❤ by GitHub

If you would rather save it to the $sugar_config instead of the database you can use the Configurator class:

<?php
require_once 'modules/Configurator/Configurator.php';
$configurator = new Configurator();
$configurator->loadConfig();
$configurator->config['abc_module_api_url'] = $_REQUEST['api_url'];
$configurator->saveConfig();