Skip to content

Php api

Aliveforms provides PHP API to execute on server. Programmer can write PHP snippets and take advantage of loops etc.

How it works

For security purposes, Aliveforms allows very few functions to be run from snippets. It works by returns an array of recommendations.

What are recommendations in PHP API?

Each recommendation is array and it is 1:1 mapping of actions in visual editor.

What is purpose of providing this?

The purpose is to speed things up. For example, if there are 5 questions with 4 options each. To assign groups upon different answers on server, it will require 5*4+1 conditions. While in PHP logic unit, loops and arrays can be used.

Available elements in PHP API

In PHP logic unit, programmer has access to * inputs * functions

Available functions in PHP API

In PHP api, for security reasons, few functions are available. * is_array * in_array

Example of PHP API

$r = [];
$r[] = ['SET_MESSAGE', 'Hello, World'];
$score = 0;

if ($inputs[0] == 0) {
  $score++;
}

if ($inputs[1] == 'meow') {
  $score++;
}

$r[] = ['APPEND_TO_MESSAGE', "Score is $score"];
$r[] = ['REDIRECT', "https://aliveforms.com"];

return $r;

Anatomy of Recommendation

A recommendation is an array of two or more element. * String: action code * ...any: action arguments

Check action codes

Action Codes

Recommendations can have following actions codes.

Code Args Purpose
SET_TOTAL 1 Sets Total Score
DECREASE_TOTAL 1 Decrease total score by give value
INCREASE_TOTAL 1 Increase total score by give value
MULTIPLY_TOTAL 1 Multiple total score by give value
SET_MESSAGE 1 Sets server message
PREPEND_TO_MESSAGE 1 Adds text before server message
APPEND_TO_MESSAGE 1 Adds text after server message
SET_GROUP_VALUE 2 Sets a group's value. 1st argument is group name, second is value
ADD_GROUP_VALUE 2 Adds to a group's value. 1st argument is group name, second is value
MULTIPLY_GROUP_VALUE 2 Multiplies a group's value. 1st argument is group name, second is value
REDIRECT 1 Redirects to url
ALERT 1 Shows alert message
MULTIPLY_SCREEN_SCORE 2 Multiplies a screens's value. 1st argument is screen index, second is value.
ADD_TO_SCREEN_SCORE 2 Multiplies a screens's value. 1st argument is screen index, second is value.
REMOVE_INTEGRATION 1 Removes integration from list. argument is ID of integration.

Doing Division

To use division, use multiplication with numbers in decimal values like 0.5

Doing Subtraction

To subtract, use addition with negative values.