While most modifications to the Form Processing Flow should exist as custom actions, there are some circumstances for otherwise filtering the data at different places during the flow.
The general flow works in the following order:
- Field Validation
- Field Processing
- Action Processing
Before Processing
Before the form is processed, form submission data is filterable using the ninja_forms_submit_data hook:
FILTER: apply_filters( ‘ninja_forms_submit_data’, $form_data );
The passed array parameter contains field data, form settings, and extra data submitted by the form.
<?php | |
add_filter( 'ninja_forms_submit_data', 'my_ninja_forms_submit_data' ); | |
function my_ninja_forms_submit_data( $form_data ) { | |
foreach( $form_data[ 'fields' ] as $field ) { // Field settigns, including the field key and value. | |
if( 'my_key' != $field[ 'key' ] ) continue; // Check the field key to see if this is the field that I need to update. | |
$field[ 'value' ] = 'foo'; // Update the submitted field value. | |
} | |
$form_settings = $form_data[ 'settings' ]; // Form settings. | |
$extra_data = $form_data[ 'extra' ]; // Extra data included with the submission. | |
return $form_data; | |
} |
Field Validation
During field validation each field’s settings are filtered before calling the respective field’s validate() method.
FILTER: ninja_forms_pre_validate_field_settings
<?php | |
add_filters( 'ninja_forms_pre_validate_field_settings', 'my_ninja_forms_pre_validate_field_settings' ); | |
function my_ninja_forms_pre_validate_field_settings( $field_settings ) { | |
return $field_settings; | |
} |
Field Processing
Each field’s registered type has a process() method by which a field’s data can be modified before actions are processed.
See: Field Registration
Action Processing
Before being processed, the form’s actions are filterable. This is a good place to dynamically remove any actions from processing.
FILTER: ninja_forms_submission_actions
<?php | |
add_filter( 'ninja_forms_submission_actions', 'my_ninja_forms_submission_actions', 10, 2 ); | |
function my_ninja_forms_submission_actions( $actions, $form_data ) { | |
return $actions; | |
} |
Before each individual form action is processed, its settings are filterable.
FILTER: ninja_forms_run_action_settings
<?php | |
add_filter( 'ninja_forms_run_action_settings', 'my_ninja_forms_run_action_settings', 10, 4 ); | |
function my_ninja_forms_run_action_settings( $action_settings, $form_id, $action_id, $form_settings ) { | |
return $action_settings; | |
} |
Before an action is triggered, a filter runs to determine if that action should be processed.
<?php | |
$type = 'email'; | |
add_filter( 'ninja_forms_run_action_type_' . $type, 'my_ninja_forms_run_action_type' ); | |
function my_ninja_forms_run_action_type( $run ) { | |
return false; | |
} |
FILTER: ninja_forms_run_action_type_$type
After Processing
Lastly, after the submission processing, an action hook fires with the relevant form data.
<?php | |
add_action( 'ninja_forms_after_submission', 'my_ninja_forms_after_submission' ); | |
function my_ninja_forms_after_submission( $form_data ){ | |
// Do stuff. | |
} |
ACTION: ninja_forms_after_submission`