Skip to content

Commit

Permalink
Merge pull request #302 from infinum/form/addons
Browse files Browse the repository at this point in the history
updating addon docs
  • Loading branch information
iruzevic authored Feb 13, 2024
2 parents f507baa + e37982a commit e5ff492
Show file tree
Hide file tree
Showing 19 changed files with 213 additions and 2 deletions.
6 changes: 6 additions & 0 deletions website/forms/addons/create/addon-boilerplate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: addon-boilerplate
title: Add-on boilerplate
---

*Coming soon*
2 changes: 1 addition & 1 deletion website/forms/addons/create/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id: intro
title: Intro
---

**Coming soon**
*Coming soon*
6 changes: 6 additions & 0 deletions website/forms/addons/create/requirements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: requirements
title: Requirements
---

*Coming soon*
6 changes: 6 additions & 0 deletions website/forms/addons/create/utils-library.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: utils-library
title: Utils library
---

*Coming soon*
12 changes: 12 additions & 0 deletions website/forms/addons/free/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
id: intro
title: Intro
---

**Free plugins:**
* *Coming soon*


## How to download?

All free plugins are publicly available and can be downloaded from our GitHub account. How to install them please follow [this tutorial](/forms/basics).
14 changes: 14 additions & 0 deletions website/forms/addons/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
id: intro
title: Intro
---

Starting from version 3 of Eightshift Forms, custom add-on plugins are now supported, which can be used along with the main plugin to enhance its functionality.

We will update this page's list of [free](free/intro) and [premium](premium/intro) plugins available for Eightshift Forms.

### Want to create your own add-on plugin?

If you want to add your add-on plugin to our list, you can submit an [issue here](https://github.com/infinum/eightshift-forms/issues).

Visit this [link](create/intro) for a tutorial and guidelines on creating a plugin for Eightshift Forms.
23 changes: 23 additions & 0 deletions website/forms/addons/premium/computed-fields/blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
id: blocks
title: Blocks
---

## Computed fields results block

Once you create your valid program and populate output variables, you should provide a [thank you](/forms/features/success-redirect) page in the `General settings`.

You can add a new `computed fields results` block on the _Thank you_ page and provide condition options.

Under `variable name`, you can provide the name of any variable defined in the `output variables`.

Under `variable value`, you can define the value of the selected variable.

When the results block is used, you can `show` any block or multiple blocks when the `computed fields program` returns a value for the selected variable.

![Computed Fields screen](/img/forms/addon-computed-fields-results.webp)

:::note
Computed fields program result is passed to the thank you page using the `es-data` GET parameter.
The passed value is encrypted and can be decrypted using the `esFormsDecryptor` function.
:::
17 changes: 17 additions & 0 deletions website/forms/addons/premium/computed-fields/data-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
id: data-flow
title: Data flow
---

Here's how data flow in the Computed fields add-on works:

1. **User input** - User fills in and submits the form.
2. **Computed Fields** - Computed Fields add-on takes the user input and processes it using the defined program.
3. **Output** - Result is returned to JavaScript through the custom key in the Forms API response data.
4. **Frontend** - JavaScript takes the result and redirects the user to the _Thank you_ page.
5. **Thank you page** - A block displays the result to the user on the Thank you page.
6. **Computed Fields Results block** - Computed Fields Results block takes the result using the `GET` variable `es-data` and displays it to the user if the conditions are met.

:::note
Multiple Computed Fields Results blocks can be used on a _Thank you_ page, but only one variable name can be used per block.
:::
16 changes: 16 additions & 0 deletions website/forms/addons/premium/computed-fields/how-to-use.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
id: how-to-use
title: How to use?
---

To use Computed Fields, you must:

1. Install and activate the add-on plugin.
2. Enable Computed fields in Global settings.
3. Create a form using Eightshift forms. (either from scratch or an integration)
4. Enable the add-on feature in the Form settings.
5. Enter the _Computed fields_ program.
6. Populate the _Output variables_ fields.
7. Add a _Computed Fields Results_ block on the _Thank you_ page.

![Computed Fields screen](/img/forms/addon-computed-fields.webp)
31 changes: 30 additions & 1 deletion website/forms/addons/premium/computed-fields/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,33 @@ id: intro
title: Intro
---

**Coming soon**
Computed Fields add-on provides the ability to do more advanced calculations and complex logic using a custom, PHP-based programming language. Multiple output variables can be set to further customize the output.

## What are Computed Fields?

_Forms computed language_ (FCL) is a subset of PHP designed to be safe to execute when the code entered is arbitrary user input, while allowing users to manipulate variables, use flow control features and run functions.

It relies on `@nikic/php-parser` to produce an abstract syntax tree, and implements a `virtual machine` for evaluating a subset of PHP tokens in a safe manner in PHP.

## Supported features and tokens

* Basic variables (numeric, boolean and string types)
* Fetching constants from PHP
* Arithmetic and logical operators (`+, -, /, *, !, &&, ||`)
* Assignment operators (`+=, .= etc.`)
* Comparison operators (`<, <=, ==`), string concatenation
* `if/elseif/else` blocks
* The ternary `if ? then : else` operator
* Unary plus and minus (e.g. `-1, +1` are valid)
* Function calls to FCL-provided functions (`currently`, `countSelectedItems`, `round` and `isSelected`)

## Notably missing or different

* Arrays can't be defined or manipulated with using FCL, apart from arrays that are defined during VM initialization (which can be counted and checked to see if an entry exists)
* `++`, `--` and `===` operators
* `switch` and `match` blocks
* User-defined functions
* OOP and namespaces
* References and unpacking
* Superglobals (`$_GET` etc.)
* Output to `stdout`, files etc. (you can not echo anything)
55 changes: 55 additions & 0 deletions website/forms/addons/premium/computed-fields/settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
id: settings
title: Settings
---

## Computed fields setting

Here you can input your FCL program. Check the _Computed fields intro_ chapter for the list of supported features.

_Available field names_ show all the form fields whose outputs are available as variables that can be used in an FCL program.

For example, if you have a field named `email`, you can use `$email` to get that field's value.

:::caution
If a field name contains special characters or spaces, use the `camelCased` version of the name for the variable. For example, `my-field` becomes `$myField`.
:::

:::note
The code editor supports syntax highlighting, undos and indenting with tabs.
:::

![Computed Fields settings 1 screen](/img/forms/addon-computed-fields-settings1.webp)

## Output variables setting

The variables sent as output data of an FCL program need to be specified manually. There is no limit for number of variables that can be output.

:::caution
Specify one variable per line and prefix each with `$`.
:::

![Computed Fields settings 2 screen](/img/forms/addon-computed-fields-settings2.webp)

## Fake fields setting

_Fake fields_ allow you to test an FCL program by providing test input data in JSON format. They will not be used on any user-facing forms.

:::note
The code editor supports syntax highlighting, undos and indenting with tabs.
:::

![Computed Fields settings 3 screen](/img/forms/addon-computed-fields-settings3.webp)

## Test your program

In order to test an FCL program without having to build a form follow these steps:

* Add the FCL program in the _Computed fields_ field.
* Populate _Output variables._
* Add test data into _Fake fields._
* Save the settings
* Click the _Test Computed_ button and check the _Output log._


![Computed Fields settings 4 screen](/img/forms/addon-computed-fields-settings4.webp)
11 changes: 11 additions & 0 deletions website/forms/addons/premium/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
id: intro
title: Intro
---

**Premium plugins:**
* [Computed fields](/forms/addons/premium/computed-fields/intro)

## How to purchase?

Premium plugins are not included with Eightshift Forms and have to be purchased separately. For more info, [drop us an e-mail](mailto:support.eightshift-forms@infinum.com).
16 changes: 16 additions & 0 deletions website/sidebars-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,28 @@ module.exports = {
'tutorials/playlist',
],
'Addon plugins': [
'addons/intro',
{
'type': 'category',
'label': 'Free',
'items': [
'addons/free/intro',
],
},
{
'type': 'category',
'label': 'Premium',
'items': [
'addons/premium/intro',
{
'type': 'category',
'label': 'Computed fields',
'items': [
'addons/premium/computed-fields/intro',
'addons/premium/computed-fields/how-to-use',
'addons/premium/computed-fields/settings',
'addons/premium/computed-fields/blocks',
'addons/premium/computed-fields/data-flow',
],
},
],
Expand All @@ -376,6 +389,9 @@ module.exports = {
'label': 'Create an addon',
'items': [
'addons/create/intro',
'addons/create/utils-library',
'addons/create/requirements',
'addons/create/addon-boilerplate',
],
},
],
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit e5ff492

Please sign in to comment.