Description
The gravityflowformconnector_{type}_target_form_id filter can be used to customize which form certain Form Connector step types will create their entry as.
Usage
1 2 | add_filter( 'gravityflowformconnector_new_entry_target_form_id' , 'gffc_new_entry_form_id_example' , 10, 4); add_filter( 'gravityflowformconnector_form_submission_target_form_id' , 'gffc_submission_form_id_example' , 10, 4); |
Parameters
Parameter | Type | Details |
---|---|---|
$form_id | String | The ID of the target form for the current step to generate an entry of. |
$entry | Entry | The current entry. |
$form | Form | The current form. |
$step | Step | The current step. |
Examples
Customize the New Entry Step Type Form ID based on a field value
This example assumes that the form which the New Entry step is running in either:
- Has a Text field that the user provides an existing form ID.
- Has a dropdown field that is dynamically populated with existing active Form IDs stored as value
After verifying that the entry value provided is an active form, or displaying an appropriate logging message, it returns the new form ID. To effectively use it, you would also have to define a hook against gravityflowformconnector_new_entry to re-define how the field values are mapped for during the step.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | add_filter( 'gravityflowformconnector_new_entry_target_form_id' , 'jo_identify_custom_form_id_new_entry' , 10, 5 ); function jo_identify_custom_form_id_new_entry ( $target_form_id , $entry , $form , $step ) { //Limit this filter to apply to specific step IDs if ( ! in_array( $step ->get_id(), array ( '214' , '215' ) ) ) { return $target_form_id ; } //Verify the field ID in the source form where the form ID is stored. $target_form_field_id = '4' ; $new_target_form_id = $entry [ $target_form_field_id ]; $new_target_form = GFAPI::get_form( $new_target_form_id ); if ( $new_target_form && $new_target_form [ 'is_active' ] == '1' ) { return $new_target_form [ 'id' ]; } gravity_flow()->log_debug( __METHOD__ . '(): No active form found for the chosen form ID. Form ID: ' . $new_target_form ); return $target_form_id ; } |
Customize the Form Submission Step Type Form ID based on a field value
This example does the same as the New Entry step type example above for the Form Submission step. To effectively use it, you would also have to define a hook against gravityflowformconnector_form_submission to re-define how the field values are mapped for during the step.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | add_filter( 'gravityflowformconnector_form_submission' , 'jo_identify_custom_form_id_form_submit' , 10, 5 ); function jo_identify_custom_form_id_form_submit ( $target_form_id , $entry , $form , $step ) { //Limit this filter to apply to specific step IDs if ( ! in_array( $step ->get_id(), array ( '214' , '215' ) ) ) { return $target_form_id ; } //Verify the field ID in the source form where the form ID is stored. $target_form_field_id = '4' ; $new_target_form_id = $entry [ $target_form_field_id ]; $new_target_form = GFAPI::get_form( $new_target_form_id ); if ( $new_target_form && $new_target_form [ 'is_active' ] == '1' ) { return $new_target_form [ 'id' ]; } gravity_flow()->log_debug( __METHOD__ . '(): No active form found for the chosen form ID. Form ID: ' . $new_target_form ); return $target_form_id ; } |
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?