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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Once the form is submitted we can process the form in our SaveConfig.php:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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']); |
To retrieve that setting:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('modules/Administration/Administration.php'); | |
$administration = new Administration(); | |
$administration->retrieveSettings(); | |
$api_url = $administration->settings['abc_Module_api_url']; |
If you would rather save it to the $sugar_config instead of the database you can use the Configurator class:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'modules/Configurator/Configurator.php'; | |
$configurator = new Configurator(); | |
$configurator->loadConfig(); | |
$configurator->config['abc_module_api_url'] = $_REQUEST['api_url']; | |
$configurator->saveConfig(); |
Add-On Spotlight
-
Upsert® Markdown Field
FEATUREDAdd a new field type to Studio that renders markdown for display on record views, list views, previews, and reports. -
Magic Integration for Epicor Prophet 21
FEATUREDEffortlessly Integrate SugarCRM and Epicor Prophet 21 with Magic xpi - Streamline Your Business with Seamless CRM and ERP Integration -
ProCode - AutoAddress
FEATUREDSearch, type addresses or zipcodes from up to 250 countries, or quickly select from intelligent location suggestions. Our plugin revolutionises how you input addresses in SugarCRM. **Instant. Interna... - Show more addons