FormCraft Hooks & Filters
hook: formcraft_before_save
This is triggered after the form has been successfully validation, but before it is saved to the database, or users are notified.
add_action('formcraft_before_save', 'your_function', 10, 4); function your_function($content, $meta, $raw_content, $integrations) { ... }
The function has 4 parameters:
- $content: This contains form values and meta-data, in a 2D array:
array(10) { ["Form ID"]=> string(2) "52" ["Form Name"]=> string(19) "Old Form (imported)" ["IP"]=> string(3) "::1" ["URL"]=> string(52) "http://localhost/wordpress/form-view/52?preview=true" ["Date"]=> string(11) "30 Apr 2015" ["Time"]=> string(8) "11:00 am" ["Name"]=> string(7) "Nishant" ["Favorite Fruits"]=> string(12) "Apple Orange" ["Form Content"]=> string(352) "<div><div style='float:left;vertical-align:top;width:600px;margin-bottom:10px'><div style='font-weight: bold'>Name</div><div>Jack</div></div><div style='float:left;vertical-align:top;width:600px;margin-bottom:10px'><div style='font-weight: bold'>Favorite Fruits</div><div>Apple<br>Orange</div></div><div style='display:block;clear:both'></div></div>" }
The variable $content[‘Form Content’] contains the form data formatted with basic HTML.
- $meta: This contains the form options, and meta data of all form fields
- $raw_content: This contains the form data, along with field IDs. This also contains fields settings for each field:
array(2) { [0]=> array(7) { ["label"]=> string(4) "Name" ["value"]=> string(7) "Nishant" ["identifier"]=> string(7) "field19" ["type"]=> string(11) "oneLineText" ["page"]=> int(1) ["page_name"]=> string(6) "Step 1" ["width"]=> string(4) "100%" } [1]=> array(7) { ["label"]=> string(15) "Favorite Fruits" ["value"]=> array(2) { [0]=> string(5) "Apple" [1]=> string(6) "Orange" } ["identifier"]=> string(7) "field20" ["type"]=> string(8) "checkbox" ["page"]=> int(1) ["page_name"]=> string(6) "Step 1" ["width"]=> string(4) "100%" } }
- $integrations: Array of integrations which are triggered, and which are not. Users can use conditional logic to trigger certain integrations only when some conditions are met:
array(2) { ["not_triggered"]=> array(1) { [0]=> string(9) "MailChimp" } ["triggered"]=> array(1) { [0]=> string(16) "Campaign Monitor" } }
Note: The array only draws from the list of integrations which were meant to be triggered with conditional logic. If an integration is active, but is independent on conditional logic, it will not form a part of the above array.
At this point, since the data isn’t saved, you can prevent the script from progressing further. For example, you can use this function to filter through the data, and if a certain condition is not met, throw an error, instead of allowing FormCraft to continue. To do so, first register the global variable $fc_final_response. Next, this:
global $fc_final_response; $fc_final_response['failed'] = "Oops ... this isn't going to work"; echo json_encode($fc_final_response); die();
hook: formcraft_after_save
This is triggered at the very end – after the form was validated, saved to the database, and emails were sent to notify users.
add_action('formcraft_after_save', 'your_function', 10, 4); function your_function($content, $meta, $raw_content, $integrations) { ... }
The function has 4 parameters:
- $content: This contains form values, and other meta data of the entry
- $meta: This contains the form options, and meta data of all form fields
- $raw_content: This contains the form data, along with field IDs. This accounts for multi-page forms.
- $integrations: Array of integrations which are triggered, and which are not. Users can use conditional logic to trigger certain integrations only when some conditions are met.
hook: formcraft_after_form_add
This is triggered when a new form is successfully created.
add_action('formcraft_after_form_add', 'your_function', 10, 4); function your_function($args) { ... }
The function has 1 parameter:
- $args: This contains the form id, creation type (blank form, duplicate, template … etc), and the form name.
(Added in version 3.2.21)
hook: formcraft_after_form_delete
This is triggered when a new form is successfully created.
add_action('formcraft_after_form_delete', 'your_function', 10, 4); function your_function($id) { ... }
The function has 1 parameter:
- $id: This is the form id.
(Added in version 3.2.21)
filter: formcraft_filter_entry_content
function my_function($entry_content) { /* Your Code to Edit $entry_content */ return $entry_content; } add_filter('formcraft_filter_entry_content', 'my_function');
The function has 1 parameter: $entry_content, which contains the form entry data submitted by the user, along with meta data for each field. You can use this filter to modify the form data.