FormBuilder: Processor
The FormBuilderProcessor class handles the rendering and processing of forms for Form Builder.
This class also contains the most commonly hooked methods in FormBuilder. Please note that this is a class you typically wouldn't call methods from. Instead, most interactions with this class are by hooking its methods.
$forms->addHook('FormBuilderProcessor::methodName', function(HookEvent $e) {
$pro = $event->object; // get FormBuilderProcessor
// ...hook code...
});
// Example
$forms->addHookBefore('FormBuilderProcessor::renderReady', function(HookEvent $event) {
$pro = $event->object; // FormBuilderProcessor instance
$form = $pro->getInputfieldForm();
if($pro->formName == 'foo') {
// do something for form named "foo"
} else if($pro->formName == 'bar-baz') {
// do something else for form named "bar-baz"
}
}); Where to place FormBuilder hooks?
Hooks can be added anywhere before a form is rendered, for instance in a template file. But depending on the embed method and version, these are common locations:
| File | Description |
|---|---|
/site/ready.php | Works anywhere and in any version |
/site/templates/FormBuilder/hooks.php | Requires FormBuilder 0.5.7 or newer |
/site/templates/FormBuilder/hooks-formName.php | Requires FormBuilder 0.5.7 and newer |
/site/templates/admin.php | Useful if hooks needed in admin only, works in any version |
/site/templates/_init.php | Works only if already using an _init.php, hooks affect front-end only |
/site/templates/form-builder.php | Placing hooks at the top of this file targets just embed methods A and B |
/site/templates/form-builder.inc | The original FormBuilder hooks file, supported by all versions |
Using the hooks.php or hooks-formName.php (replacing formName with actual form name) is preferable when available, as they
are loaded only when a form will be rendered or processed.
Processor plugin modules
You can use or create FormBuilderProcessorAction modules to automatically plug-in to any part of the form life cycle. This is ideal if you want to add hook-like functionality that can easily be shared, configured and enabled/disabled on a per-form basis.
Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the FormBuilderProcessor class also inherits all the methods and properties of: WireData and Wire.
- Rendering
- Processing
- Entries
- Pages
- Auto responder
- Spam
- Other actions
- Output
- Success
- Errors
- Submit
- Form
- Session
- Settings
- Other
- Save flags
- Form flags
- Spam flags
Rendering
| Name | Return | Summary | |
|---|---|---|---|
$processor->render() $processor->render() $processor->render($id = null) | string | Return the rendered form output, whether an actual form or the success message after submitted. | |
$processor->renderOrProcessReady() $processor->renderOrProcessReady(InputfieldForm $form, int $submitType) $processor->renderOrProcessReady(InputfieldForm $form, int $submitType) | None | Hook called when form is ready to be rendered OR processed | |
$processor->renderReady() $processor->renderReady(InputfieldForm $form) $processor->renderReady(InputfieldForm $form, string $formFile = '', array $vars = []) | string | Hook called right before form is rendered, and it returns the rendered form output | |
$processor->renderSubmitKey() $processor->renderSubmitKey() $processor->renderSubmitKey(string $submitKey = '') | string | Render the submitKey in a hidden form field, ready to be output | |
$processor->wrapOutput() $processor->wrapOutput(string $out) $processor->wrapOutput(string $out) | string | Wraps all FormBuilder output |
Processing
Entries
Pages
| Name | Return | Summary | |
|---|---|---|---|
$processor->emailForm() $processor->emailForm(InputfieldForm $form, array $data) $processor->emailForm(InputfieldForm $form, array $data, string $emailTo = '') | bool int | Email the form result to the administrator(s) | |
$processor->emailFormPopulateSkipFields() $processor->emailFormPopulateSkipFields(FormBuilderEmail $email, InputfieldForm $form) $processor->emailFormPopulateSkipFields(FormBuilderEmail $email, InputfieldForm $form) | None | Hookable method for populating fields that should be skipped in an email | |
$processor->emailFormReady() $processor->emailFormReady(InputfieldForm $form, FormBuilderEmail $email) $processor->emailFormReady(InputfieldForm $form, FormBuilderEmail $email) | bool | Hook called before email is sent to administrator | |
| $processor->emailFrom | string | Email address (or field name where it resides) to use as the reply-to address for the email. | |
| $processor->emailFrom2 | string | Email FROM address, if different the one specified in module settings and reply-to address. | |
| $processor->emailFromName | string | Email from name | |
| $processor->emailSubject | string | subject of email that gets sent | |
| $processor->emailTo | string | Email address to send form submissions to, may also be multiple (1 per line) or conditional (1 condition per line) | |
| $processor->mailer | string | Name of WireMail module to use for sending email, 'WireMail' for native PHP mail(), or blank for auto-detect. |
Auto responder
| Name | Return | Summary | |
|---|---|---|---|
$processor->emailFormResponder() $processor->emailFormResponder(InputfieldForm $form, array $data) $processor->emailFormResponder(InputfieldForm $form, array $data) | bool | Email the form result to the sender (auto-responder) | |
$processor->emailFormResponderReady() $processor->emailFormResponderReady(InputfieldForm $form, FormBuilderEmail $email) $processor->emailFormResponderReady(InputfieldForm $form, FormBuilderEmail $email) | bool | Hook called before email is sent to autoresponder, see details for example | |
| $processor->responderBody | string | Body for the responder email | |
| $processor->responderFrom | string | Email address that the responder email should be from | |
| $processor->responderFromName | string | Name responder should be from | |
| $processor->responderReplyTo | string | Responder reply-to address | |
| $processor->responderSubject | string | Subject line for the responder email | |
| $processor->responderTo | string | field name (not email address) that WILL contain the submittor's email address (where the responder should be sent). CSV string for multiple. |
Spam
| Name | Return | Summary | |
|---|---|---|---|
| $processor->akismet | string | CSV string containing field names of: "name,email,content" (in that order) | |
| $processor->honeypot | string array | name of field that, when populated, invalidates the form submission (or array of them) | |
$processor->isSpam() $processor->isSpam() $processor->isSpam() | bool string | Returns name of triggered spam filter when entry detected as spam | |
$processor->processInputIsSpam() $processor->processInputIsSpam(InputfieldForm $form, bool $processed) $processor->processInputIsSpam(InputfieldForm $form, bool $processed) | string | Does given processed form contain spam? | |
$processor->processInputSpammed() $processor->processInputSpammed(InputfieldForm $form, string $spamType) $processor->processInputSpammed(InputfieldForm $form, string $spamType) | None | Hook called when processInput fails due to being spammed | |
| $processor->spamFlags | int | Spam flags | |
| $processor->spamTimer | int | Time required between render and submit for form to be considered valid | |
| $processor->spamWords | array | Keywords that flag a form submission as spam. | |
| $processor->turingTest | array | array containing list of field names and required answers |
Other actions
| Name | Return | Summary | |
|---|---|---|---|
| $processor->action2 | string | URL to send duplicate submission to | |
| $processor->action2_add | array | array of name=value to add to duplicate submission | |
| $processor->action2_remove | array | array of field names to remove from duplicate submission | |
| $processor->action2_rename | array | array of field names rename before duplicate submission | |
| $processor->googleSheetsResponseField | string | Name of field to poulate with Google Sheets response (which indicates row and column) | |
| $processor->googleSpreadsheetFields | array | ||
| $processor->googleSpreadsheetUrl | string | ||
$processor->postAction2() $processor->postAction2(array $data) $processor->postAction2(array $data) | bool | Post a duplicate copy of the form submission/entry to another URL | |
$processor->postAction2Ready() $processor->postAction2Ready(WireHttp $http, array $data, string $method, string $url, array $headers) $processor->postAction2Ready(WireHttp $http, array $data, string $method, string $url, array $headers) | bool string | Called right before we send a duplicate copy to another URL | |
$processor->saveGoogleSheets() $processor->saveGoogleSheets(InputfieldForm $form, array $data) $processor->saveGoogleSheets(InputfieldForm $form, array $data) | bool | Save to Google Sheets | |
$processor->saveGoogleSheetsReady() $processor->saveGoogleSheetsReady(GoogleSheets $sheets, array $row, array $data) $processor->saveGoogleSheetsReady(GoogleSheets $sheets, array $row, array $data) | array | Hook called before spreadsheet row saved, can optionally modify $event->return (spreadsheet row) |
Output
| Name | Return | Summary | |
|---|---|---|---|
$processor->appendMarkup() $processor->appendMarkup(string $markup) $processor->appendMarkup(string $markup) | None | Add markup to append to the form | |
| $processor->dupMessage | string | message to display when form is already submitted / duplicate submission | |
| $processor->errorMessage | string | message to display when a form error occurred | |
$processor->renderError() $processor->renderError(string $error) $processor->renderError(string $error, string $errorTemplate = '') | string | Render an error message into markup | |
$processor->renderSuccess() $processor->renderSuccess(string $message) $processor->renderSuccess(string $message) | string | Render the given success message for output | |
$processor->renderSuccessMessage() $processor->renderSuccessMessage(string $message) $processor->renderSuccessMessage(string $message, string $markupTemplate = '') | string | Render a success message | |
$processor->renderSuccessRedirect() $processor->renderSuccessRedirect(string $url) $processor->renderSuccessRedirect(string $url) | string | Render a success redirect | |
| $processor->submitText | string | text that appears on the submit button | |
| $processor->successMessage | string | message to display on successful form submission, assuming no successUrl was set | |
| $processor->successUrl | string | URL to redirect to on successful form submission |
Success
| Name | Return | Summary | |
|---|---|---|---|
$processor->formSubmitSuccess() $processor->formSubmitSuccess(InputfieldForm $form) $processor->formSubmitSuccess(InputfieldForm $form) | None | Called upon successful form submission | |
$processor->renderSuccess() $processor->renderSuccess(string $message) $processor->renderSuccess(string $message) | string | Render the given success message for output | |
$processor->renderSuccessMessage() $processor->renderSuccessMessage(string $message) $processor->renderSuccessMessage(string $message, string $markupTemplate = '') | string | Render a success message | |
$processor->renderSuccessRedirect() $processor->renderSuccessRedirect(string $url) $processor->renderSuccessRedirect(string $url) | string | Render a success redirect | |
| $processor->successMessage | string | message to display on successful form submission, assuming no successUrl was set | |
| $processor->successUrl | string | URL to redirect to on successful form submission |
Errors
Submit
| Name | Return | Summary | |
|---|---|---|---|
$processor->getSubmitType() $processor->getSubmitType() $processor->getSubmitType() | bool int null | Get the form submit type | |
$processor->getValues() $processor->getValues() $processor->getValues() | array | Get an array of all values from this form | |
$processor->isSpam() $processor->isSpam() $processor->isSpam() | bool string | Returns name of triggered spam filter when entry detected as spam | |
$processor->isSubmitted() $processor->isSubmitted() $processor->isSubmitted() | bool | Was the form successfully submitted? (for public API) | |
$processor->setSubmitType() $processor->setSubmitType($submitType) $processor->setSubmitType($submitType) | None | Set the form submit type |
Form
| Name | Return | Summary | |
|---|---|---|---|
$processor->getFbForm() $processor->getFbForm() $processor->getFbForm() | FormBuilderForm | Get current FormBuilderForm object | |
$processor->getInputfield() $processor->getInputfield(string $name) $processor->getInputfield(string $name) | Inputfield null | Get Inputfield from form by field name | |
$processor->getInputfieldForm() $processor->getInputfieldForm() $processor->getInputfieldForm() | InputfieldForm | Get the constructed form (alias of getInputfieldsForm) | |
$processor->getInputfieldsForm() $processor->getInputfieldsForm() $processor->getInputfieldsForm() | InputfieldForm | Get the constructed form | |
$processor->setInputfieldsForm() $processor->setInputfieldsForm(InputfieldForm $form) $processor->setInputfieldsForm(InputfieldForm $form) | None | Set the InputfieldForm |
Session
| Name | Return | Summary | |
|---|---|---|---|
$processor->sessionGet() $processor->sessionGet(string $key) $processor->sessionGet(string $key, $default = null) | mixed null | Get a session value unique for this form | |
$processor->sessionRemove() $processor->sessionRemove(string $key) $processor->sessionRemove(string $key) | None | Remove a session value unique for this form | |
$processor->sessionSet() $processor->sessionSet(string $key, mixed $value) $processor->sessionSet(string $key, mixed $value) | None | Set a session value unique for this form |
Settings
| Name | Return | Summary | |
|---|---|---|---|
| $processor->allowPreset | bool | allow form field values to be pre-set from GET variables? | |
| $processor->formName | string | name of the form | |
| $processor->framework | string | Name of form framework to use | |
| $processor->id | int | Form ID number | |
| $processor->pluginActions | array | Array of FormBuilderProcessorAction module names used as plugins to add form processing actions | |
| $processor->saveFlags | int | Flags for saving form submission DEFAULT: self::saveFlagsDB | |
| $processor->showHidden | bool | Show input[type=hidden] as type=text instead? Option may only be modified in construct $options. DEFAULT: false | |
| $processor->skipSessionKey | bool | Require a unique session key for each form submission (for security) | |
| $processor->useCookies | bool | Remember input values? | |
| $processor->validateNumFields | bool | Validate quantity of fields present in form as part of the _submitKey? |
Other
| Name | Return | Summary | |
|---|---|---|---|
$processor->getFormUrl() $processor->getFormUrl() $processor->getFormUrl(array $options = []) | string | Get the URL for the given form | |
$processor->isAdmin() $processor->isAdmin() $processor->isAdmin() | bool | Are we currently in the FormBuilder admin? | |
$processor->saveLog() $processor->saveLog(string $message) $processor->saveLog(string $message) | None | Save a log entry to the form-builder log |
Save flags
Constants used to populate the $saveFlags property, which dictates what actions to take with submitted forms. There can be multiple saveFlags so they should be applied in bitwise fashion.
| Name | Return | Summary | |
|---|---|---|---|
| FormBuilderProcessor::saveFlagAction2 const | 4 | Used when form entries should have a duplicate copy sent to a 3rd party service | |
| FormBuilderProcessor::saveFlagDB const | 1 | Used when form entries should be saved to database | |
| FormBuilderProcessor::saveFlagEmail const | 2 | Used when form entries should be sent via email to administrator | |
| FormBuilderProcessor::saveFlagExternal const | 16 | Used when the form should submit somewhere else (rendering all other save options invalid) | |
| FormBuilderProcessor::saveFlagFilterSpam const | 32 | Used when form submissions should be screened for spam | |
| FormBuilderProcessor::saveFlagGoogleSheets const | 128 | Used when form submissions should also save to Google Sheets | |
| FormBuilderProcessor::saveFlagPage const | 8 | Used when entries should be saved to new pages | |
| FormBuilderProcessor::saveFlagResponder const | 64 | Used when form submissions should include an auto-responder email | |
FormBuilderProcessor::saveFlagsLabels() FormBuilderProcessor::saveFlagsLabels() FormBuilderProcessor::saveFlagsLabels($saveFlags = null, bool $getString = false) | array string | Get array (or csv string) of text labels for given saveFlags |
Form flags
Constants used to populate the $formFlags property, which maintains form toggle settings. There can be multiple saveFlags so they should be applied in bitwise fashion.
| Name | Return | Summary | |
|---|---|---|---|
| FormBuilderProcessor::formFlagDisabled const | 4 | Used when form is disabled for accepting new entries | |
| FormBuilderProcessor::formFlagEditLinks const | 1024 | Used when edit links should be shown in form preview 0.5.7+ | |
| FormBuilderProcessor::formFlagEmailFiles const | 256 | Used when uploaded files should be included as email attachments | |
| FormBuilderProcessor::formFlagEmailSubjectId const | 512 | Used when entry ID should be included in email subjects | |
| FormBuilderProcessor::formFlagInclude const | 2 | Used when for is intended as an include for other forms | |
| FormBuilderProcessor::formFlagNoModal const | 1 | Used when modal window for admin/editing should be disabled |
Spam flags
| Name | Return | Summary | |
|---|---|---|---|
| FormBuilderProcessor::spamFlagEntry const | 8 | Specifies that we should still save spam entries but flag them as spam | |
| FormBuilderProcessor::spamFlagNone const | 0 | Specifies that default reporting should be used for spam | |
| FormBuilderProcessor::spamFlagSilent const | 2 | Specifies that spam entries should be silently discarded | |
| FormBuilderProcessor::spamFlagVerbose const | 4 | Specifies that we should notify the persion submitting the form that spam was detected |
Additional methods and properties
In addition to the methods and properties above, FormBuilderProcessor also inherits the methods and properties of these classes:
API reference based on ProcessWire core version 3.0.252