Loading...
Changes Saved.
Error Occurred!

KnowledgeBase

How to Build a Widget

ActiveCampaign products are web-based software applications written in PHP programming language. Some have support for Widgets, or standalone mini-applications that can run in designated areas of ActiveCampaign applications.

Anyone with a knowledge of PHP programming can write their own widgets for ActiveCampaign software products. Some widgets, such as Custom HTML and RSS Feed widgets, can be used in any product, while some might be tied to the application they are meant to be used in, and therefore are not usable for other ActiveCampaign products.

Widgets should follow these guidelines:

  • every widget should be located in the folder named as ID of the widget (widget folder)
  • every widget should have a file within the root widget folder named {WIDGETID}.php (widget file)
  • widget file should be a PHP file that starts with a configuration zone, structured as PHP comment
  • widget configuration zone should contain at least three pieces of information: Name, Section and Version
  • widget file should contain (or include) a class named AC_Widget_{WIDGETID} which should extend the class AC_Widget (widget class)
  • widget class should have a method show(), called with no parameters; this method is called to display the widget
  • if needed, additional methods can be added:
    • form() - displays a configuration form; if any settings are needed, print the form fields to set them here
    • save() - creates a configuration array to save for this widget instance; should accept form fields from form()
    • install() - runs when widget is added to the bar
    • uninstall() - runs when widget is removed from the bar
  • widget methods (form() and show()) should either return the HTML to show or print it out. Any printed content will cancel out any returned one.

 

Widget Configuration Zone

At the top of the widget PHP file, within a PHP comment (Widget Configuration Zone), the following settings can be used:

  • Widget Name - widget name, used to show what widget does (*required)
  • Description - longer description of a widget, in one line
  • Version - version of the widget
  • Section - in which section of the software can it be used; allowed values are "admin", "public" and "both" (*required)
  • Widget URL - a home page of the widget
  • Author - name of the widget creator
  • Author URL - a home page of the widget creator
  • License - a license under which a widget is released
  • Products - which products can use this widget; allowed values are "hd" (Help Desk), "kb" (Knowledge Management), "em" (Email Marketing) and "sv" (Survey Management)
  • Use In - to which bars it is restricted; used for widgets that are page-dependable (allowed values vary per product; please contact support for details)

Here is the code of a simple widget:

<?php

/*
Section: BOTH
Widget Name: Simple Widget
Description: Simple Widget is the simplest widget that can be shown.
Version: 1.0
*/

class AC_Widget_simplewidget extends AC_Widget {

function form() {
if ( !isset($this->config['text']) ) $this->config['text'] = '';
?>
<div>
<?php echo _a("Text to show:"); ?><br />
<input
name="text"
id="widget_simplewidget_text_<?php echo $this->id; ?>"
value="<?php echo $this->config['text']; ?>"
/>
</div>
<?php
}

function save() {
if ( !isset($_POST['text']) ) return false;
$options = array(
'text' => (string)$_POST['text'],
);
return $options;
}

function show() {
if ( !isset($this->config['text']) ) $this->config['text'] = '';
return $this->config['text'];
}

}

?>




Related Articles