Creating Limesurvey Plugins

UPDATE 19/03/2019: Update to work on Limesurvey 3.* as well.

UPDATE 19/12/2019: Update to work on Limesurvey 3.3 and up and fixed a typo, thanks to Thirsty Turtle for the remarks!

Note: I am looking for betatesters for two really cool (I think so at least) Limesurvey integrations I wrote: A service to connect Limesurvey to Zapier, that will allow you to connect your Limesurvey responses and tokens to any platform Zapier supports (which is a lot) and a webapp that uses your Limesurvey surveys to create chatbots on Telegram and Facebook.
Interested? Contact me at beta[at]!

For our new Limesurvey management app Zest, we have created two plugins for Limesurvey, one to send a post request with certain data every time someone submits a survey, and one that anonymizes tokens after they are used. (this allows for the convenience of token based persistance while still keeping the data as anonymous as possible). In this post, I’d like to show you how to (re)create the first of these plugins, hopefully this will help make your own plugins. Another post where I do the same for the other plugin will follow shortly.

Both plugins are open source and can be freely used, you can find the code at our Github page.

Also, do not forget to take a look at the Limesurvey Wiki on Plugin development, which has a lot of useful information, as well as at the Plugin API, which shows the methods that you can use when writing your plugin.


We are going to create a plugin that makes a post request every time someone submits a survey, and the plugin can be enabled site wide but always turned on or off on a survey level, and the plugin can pass the survey id, token id, and several given answers. It will also have settings for the URL to make the request to, as well as a authorization token and a unique key for the server. While the plugin was written especially for our Zest platform, it is really easy to adapt it to whatever your implementation might need.

The final product

On the left you can see the final global settings page. As you can see it is now geared towards use for Zest, but out of the box you can change the URL to post to, but with a few changes in the code you can adapt it to use your own tokens etcetera.

In the local survey settings menu you can overwrite most of the settings for each survey separately. It is also possible to pass along the users token, as well as attach an array of question codes with the given answers.

When debug is turned on, on each submission the data is shown on screen. Here you can see the survey id, the user’s token, and three questions that were passed along as well. ‘Test’ was a free text question, ‘q01’ an equation and ‘dsa121’ a radio list.

The basics

We are first going to create a folder in the limesurvey/plugins folder, named after the plugin we are making. We are calling it ZestHook. In this folder we will create a new PHP file with the same name as the folder. Open this file in your favorite code editor and let’s get started.

Examining the example plugin

I find the easiest way to start writing a plugin is by looking at the example plugin that ships with Limesurvey, or any of the existing plugins that you can find at the plugin repository, especially if one these does something something similar to what you want to achieve. If you look at the example plugin, you can see a plugin basically exists of three parts: first we register the events we want to subscribe to (the events when we want our plugin to be called), and attach a function to the event. Next we are going to add both general settings to the plugin and settings that can be set for each survey individually. Finally, we are going to write the code that gets executed on each of the events we registered earlier. In this case, it will be the code that gets run on each survey response submission.

Extend pluginbase

We are going to start by creating our plugin class and extend the PluginBase class:

If you are developing for Limesurvey versions before 3.*:

And is you are developing for Limesurvey 3.*:

You should make sure that the classname is exactly (case sensitive) the same as the folder name.

Registering the plugin

First we are going to add some variables we want to use, and create an init() function with the events we want to register to. in our case, we want to register to the following events: afterSurveyComplete (when we will send the post request), beforeSurveySettings (to add settings for each survey), and newSurveySettings (to save these settings). For a full list of all the events check out this Limesurvey page. The code should look like this:

Adding the general settings

Our plugin is going to have several site wide options: The default URL to post to, whether to send a hook by default, our API token and the unique server id. Settings can contain several types of data, we are going to use strings and booleans for now.

The code to add these settings should look as follows:

You can see that each setting is an array, where you can define the type of setting (select or string in our case), the label that should precede it, an optional help text, default value, and if the type is a select you can add an array with the options that can be selected.

Adding survey specific settings

We want to be able to overwrite the global plugin settings at the survey level, so we are going to add these settings for each survey as well. Besides that, we’ll add a debug mode to the survey settings, so you can test the connection and see what data gets transmitted. We are going to use the event that we registered earlier for: beforeSurveySettings, and create a function with the same name that will be called whenever this event is broadcast.

As you can see we have also added a few select question on whether to overwrite the global settings, as well as a Answers to send question, where you can enter a comma separated list of question codes whose answers you want to send along with the hook. (useful if you want to register a calculated score, of an e-mailadres that was entered)

We will also need to able to save these settings, so next we will create a function to do so that gets called on the newSurveySettings event.

This will loop through all the settings and save them.

Sending the hook

Finally, we get to write the code that will send the POST request. On firing of the afterSurveyComplete event, the afterSurveyComplete() function will execute.

First, we will check whether we should send a webhook. The isHookDisabled function will check this, and return a boolean. If the hook is not enabled, we will return immediately. The isHookDisabled function is a simple one:

It first checks if the webhook is enabled on the survey level:

If the value is not set to no, we will then check if the survey settings is set to ‘use global settings’ and the global setting is set to no.

If the value is not set to no, we will then check if the survey settings is set to ‘use global settings’ and the global setting is set to yes.

The code will then continue to get the relevant data, and eventually send the post request / webhook. The finished code looks like this:

As you can we retrieve the necessary data such as the url to post to, the authentication and server token, the users token, and any additional fields and answers that need to be send along. This data then gets posted to the url, and if the debug setting is on, the response is printed on the screen. If you look at the code you can see how to retrieve certain fields, both on a global server lever or specific survey settings.


Hopefully this example plugin can help you to create your own plugins for Limesurvey! The full and complete code can be found on Github, feel free to use it, fork it, improve it or create your own plugins with it. If you have any questions feel free to reach me at stefan [at]

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store