Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions gp-populate-anything/gppa-force-gppa-on-save-and-continue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Gravity Perks // Populate Anything // Force GPPA value over a Save & Continue Value
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
*/
add_filter( 'gform_incomplete_submission_post_get', function( $submission_json, $resume_token, $form ) {
// Update "29" to your form ID, and "1" to your field ID
$target_form_id = 29;
$target_field_id = 1;
static $_gppa_forcing_hydration;
if ( $form['id'] == $target_form_id && ! $_gppa_forcing_hydration ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a check for the field ID here? You might need to introduce a foreach as being able to specify multiple fields would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha!

$_gppa_forcing_hydration = true;
$submission = json_decode( $submission_json, ARRAY_A );
$field = GFAPI::get_field( $form, $target_field_id );
$hydrated_field = gp_populate_anything()->hydrate_field( $field, $form, array(), null, false );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing array() for field values, it might be helpful to pass the draft entry that way if something relies on another field's value to populate, it'll populate correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha!

$submission['submitted_values'][$target_field_id] = $hydrated_field['field_value'];
$submission_json = json_encode( $submission );
$_gppa_forcing_hydration = false;
}
return $submission_json;
}, 10, 3 );