fihooks.class.php

FormIt

Copyright 2009-2011 by Shaun McCormick shaun@modx.com

FormIt is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

FormIt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with FormIt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package
formit

\fiHooks

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.

package
formit

Properties

Propertypublicarray  $errors= 'array'

A collection of all the processed errors so far.

Default valuearrayDetails
Type
array
access
public
Propertypublicarray  $fields= 'array'

The current stored and parsed fields for the FormIt call.

Default valuearrayDetails
Type
array
Propertypublic\FormIt  $formit= 'null'

A reference to the FormIt instance.

Default valuenullDetails
Type
\FormIt
access
public
Propertypublicarray  $hooks= 'array'

A collection of all the processed hooks so far.

Default valuearrayDetails
Type
array
access
public
Propertypublic\modX  $modx= 'null'

A reference to the modX instance.

Default valuenullDetails
Type
\modX
access
public
Propertypublicstring  $redirectUrl= 'null'

If a hook redirects, it needs to set this var to use proper order of execution on redirects/stores

Default valuenullDetails
Type
string
access
public

Methods

methodpublic  __construct( \FormIt $formit, array $config = array ) : \fiHooks
The 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
Type Description
\fiHooks
methodprivate  _loadFileBasedHook( string $path, array $customProperties = array ) : boolean
Attempt 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
Type Description
boolean
methodpublic  _process( string $str, array $placeholders = array ) : string
Processes 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
Type Description
string
methodpublic  addError( string $key, string $value ) : string
Adds an error to the stack.
Parameters
Name Type Description
$key string The field to add the error to.
$value string The error message.
Returns
Type Description
string
Details
access
private
methodpublic  email( array $fields = array ) : boolean
Send 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
Type Description
boolean
Details
access
public
methodpublic  gatherFields( ) : array
Gather fields and set them into placeholders for pre-fetching
Returns
Type Description
array
methodpublic  getErrorMessage( string $delim = \n ) : string
Gets the error messages compiled into a single string.
Parameters
Name Type Description
$delim string The delimiter between each message.
Returns
Type Description
string
Details
access
public
methodpublic  getErrors( ) : array
Get all errors for this current request
Returns
Type Description
array
methodpublic  getRedirectUrl( ) : null|string
Get the specified redirection url
Returns
Type Description
nullstring
methodpublic  getValue( string $key ) : mixed
Gets the value of a field.
Parameters
Name Type Description
$key string The field name to get.
Returns
Type Description
mixed
methodpublic  getValues( ) : array
Gets an associative array of field name and values.
Returns
Type Description
array
methodpublic  hasErrors( ) : boolean
See if there are any errors in the stack.
Returns
Type Description
boolean
methodpublic  load( string $hookName, array $fields = array, array $customProperties = array ) : boolean
Load 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
Type Description
boolean
Details
access
public
methodpublic  loadMultiple( array $hooks, array $fields = array, array $customProperties = array ) : array
Loads 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
Type Description
array
Details
access
public
methodpublic  math( array $fields = array ) : boolean
Math field hook for anti-spam math input field.
Parameters
Name Type Description
$fields array An array of cleaned POST fields
Returns
Type Description
boolean
Details
access
public
methodpublic  processErrors( ) : void
Process any errors returned by the hooks and set them to placeholders
methodpublic  recaptcha( array $fields = array ) : boolean
Adds in reCaptcha support to FormIt
Parameters
Name Type Description
$fields array An array of cleaned POST fields
Returns
Type Description
boolean
Details
access
public
methodpublic  redirect( array $fields = array ) : boolean
Redirect 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
Type Description
boolean
methodpublic  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
methodpublic  setValue( string $key, mixed $value ) : mixed
Sets 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
Type Description
mixed
methodpublic  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.

methodpublic  spam( array $fields = array ) : boolean
Ensure 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
Type Description
boolean
Details
access
public
Documentation was generated by DocBlox 0.13-DEV.