Base Hooks handling class. Hooks can be used to run scripts prior to loading the form, or after a form has been
submitted.
Hooks can be either a predefined list by FormIt, or custom MODX Snippets. They can also be chained to allow for
order-of-execution processing. Returning false from a Hook will end the chain. Returning false in a postHook will
prevent the form from being further submitted.



__construct(
\FormIt $formit, array $config
=
array
)
:
\fiHooksThe constructor for the fiHooks class
Parameters
| Name |
Type |
Description |
| $formit |
\FormIt |
&$formit A reference to the FormIt class instance.
|
| $config |
array |
Optional. An array of configuration parameters. |
Returns



_loadFileBasedHook(
string $path, array $customProperties
=
array
)
:
booleanAttempt to load a file-based hook given a name
Parameters
| Name |
Type |
Description |
| $path |
string |
The absolute path of the hook file |
| $customProperties |
array |
An array of custom properties to run with the hook |
Returns



_process(
string $str, array $placeholders
=
array
)
:
stringProcesses string and sets placeholders
Parameters
| Name |
Type |
Description |
| $str |
string |
The string to process |
| $placeholders |
array |
An array of placeholders to replace with values |
Returns



addError(
string $key, string $value
)
:
stringAdds an error to the stack.
Parameters
| Name |
Type |
Description |
| $key |
string |
The field to add the error to. |
| $value |
string |
The error message. |
Returns
Details
- access
- private



email(
array $fields
=
array
)
:
booleanSend an email of the form.
Properties:
- emailTpl - The chunk name of the chunk that will be the email template.
This will send the values of the form as placeholders.
- emailTo - A comma separated list of email addresses to send to
- emailToName - A comma separated list of names to pair with addresses.
- emailFrom - The From: email address. Defaults to either the email
field or the emailsender setting.
- emailFromName - The name of the From: user.
- emailSubject - The subject of the email.
- emailHtml - Boolean, if true, email will be in HTML mode.
Parameters
| Name |
Type |
Description |
| $fields |
array |
An array of cleaned POST fields |
Returns
Details
- access
- public



getErrorMessage(
string $delim
=
\n
)
:
stringGets the error messages compiled into a single string.
Parameters
| Name |
Type |
Description |
| $delim |
string |
The delimiter between each message. |
Returns
Details
- access
- public



getRedirectUrl(
)
:
null|stringGet the specified redirection url
Returns
| Type |
Description |
| nullstring |
|



getValue(
string $key
)
:
mixedGets the value of a field.
Parameters
| Name |
Type |
Description |
| $key |
string |
The field name to get. |
Returns



load(
string $hookName, array $fields
=
array, array $customProperties
=
array
)
:
booleanLoad a hook. Stores any errors for the hook to $this->errors.
Parameters
| Name |
Type |
Description |
| $hookName |
string |
The name of the hook. May be a Snippet name. |
| $fields |
array |
The fields and values of the form. |
| $customProperties |
array |
Any other custom properties to load into a custom hook. |
Returns
Details
- access
- public



loadMultiple(
array $hooks, array $fields
=
array, array $customProperties
=
array
)
:
arrayLoads an array of hooks. If one fails, will not proceed.
Parameters
| Name |
Type |
Description |
| $hooks |
array |
The hooks to run. |
| $fields |
array |
The fields and values of the form |
| $customProperties |
array |
An array of extra properties to send to the hook |
Returns
Details
- access
- public



math(
array $fields
=
array
)
:
booleanMath field hook for anti-spam math input field.
Parameters
| Name |
Type |
Description |
| $fields |
array |
An array of cleaned POST fields |
Returns
Details
- access
- public



recaptcha(
array $fields
=
array
)
:
booleanAdds in reCaptcha support to FormIt
Parameters
| Name |
Type |
Description |
| $fields |
array |
An array of cleaned POST fields |
Returns
Details
- access
- public



redirect(
array $fields
=
array
)
:
booleanRedirect to a specified URL.
Properties needed:
- redirectTo - the ID of the Resource to redirect to.
Parameters
| Name |
Type |
Description |
| $fields |
array |
An array of cleaned POST fields |
Returns



setRedirectUrl(
string $url
)
:
Set a URL to redirect to after all hooks run successfully.
Parameters
| Name |
Type |
Description |
| $url |
string |
The URL to redirect to after all hooks execute |



setValue(
string $key, mixed $value
)
:
mixedSets the value of a field.
Parameters
| Name |
Type |
Description |
| $key |
string |
The field name to set. |
| $value |
mixed |
The value to set to the field. |
Returns



setValues(
array $values
=
array
)
:
Sets an associative array of field name and values.
Parameters
| Name |
Type |
Description |
| $values |
array |
A key/name pair of fields and values to set.
|



spam(
array $fields
=
array
)
:
booleanEnsure the a field passes a spam filter.
Properties:
- spamEmailFields - The email fields to check. A comma-delimited list.
Parameters
| Name |
Type |
Description |
| $fields |
array |
An array of cleaned POST fields |
Returns
Details
- access
- public