FormBuilderProcessorAction
A FormBuilder plugin module interface that enables you to easily hook into any step of form rendering or processing.
Form The Stripe Payments Processor
is an example of a Form To create a Your module class should implement one or more of the defined methods further down in the method reference, as needed, to accomplish whatever your action module is intended to do. These defined methods can also be used to add hooks anywhere in FormBuilder. So if you don’t see a specific method that you need, then any of the predefined methods can also be used to add hooks to any
part of the process. The most commonly implemented methods are Your module should be placed in the file Below is an example of the code for a FormBuilderProcessorHello module: You should also create a Test it out!
In your admin, do a Modules > Refresh and then install your module.
Edit a form and click the “Actions” tab. Check the box for your “Hello World”
action. It will open a text input where you can configure the Hello message.
Save, and then Preview your form. Now let’s take the module a little bit further, adding an action
in the admin where form entries are listed. We’ll add a “Hello” button
that can be applied to any existing form entry. In this example,
it will say "hello" to any checked entries. Silly I know, but
hopefully hints at what might be possible. This would be added
to the class from our previous code example above. Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Methods that can be optionally implemented by the module and will be called automatically by FormBuilder. Populate Inputfields to configure this action (if configurable) Set and save to DB a config value for this action/module here and in the FormBuilder form Set a config value for this action/module here and in the FormBuilder form In addition to the methods and properties above, FormCreating an action module
Form module, create a class named FormBuilderProcessorHello, optionally replacing “Hello” with the name of your action. The class should extend the Form
class located in /site/modules/FormBuilder/. actionReady() and formReady().FormBuilderProcessorHello.module.php in the directory
/site/modules/FormBuilderProcessorHello/ (optionally replacing “Hello” with the name of your action). // FormBuilder Processor Action: Hello World
// Displays a "hello world" or custom message above any rendered form
// that has this action selected on its “Actions” tab
class FormBuilderProcessorHello extends FormFormBuilderProcessorHello.info.php file
in the same directory that returns information about your module:$info = [
'title' => 'Hello world action example',
'version' => 1,
'summary' => 'Example of a FormBuilderProcessor custom action',
'icon' => 'smile-o',
'requires' => 'FormBuilder>=0.4.5',
];Taking it further
// List entries in admin
// Adds a 'hello world' action button for entries admin checks boxes for
public function adminListEntries() {
$this->addHookAfter('ProcessFormBuilderEntries::getAllowedActions', function($e) {
$actions = $e->return; // array
$actions[] = [
'name' => 'hello-world',
'label' => $this->hello_text,
'icon' => 'smile-o'
];
$e->return = $actions;
});
$this->addHookAfter('ProcessFormBuilderEntries::processActionForEntry', function($e) {
if($e->return) return; // true return value means it was already handled
$action = $e->arguments(0); // array
$entry = $e->arguments(1); // array
if($action['name'] 'hello-world') {
$this->message("$this->hello_text for entry $entry[id]!");
$e->return = true; // indicate we handled it
}
});
}Form class also inherits all the methods and properties of: WireData and Wire.Implementation
Tools
Config
Name Return Summary None self self Properties
Name Return Summary Form string Name of the current form Additional methods and properties
API reference based on ProcessWire core version 3.0.261