Skip to content

Commit 4d0519c

Browse files
authored
gpep-passthrough-consent-field.php: Added snippet for easy passthrough on Consent Field.
1 parent 7eb6216 commit 4d0519c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Easy Passthrough // Passthrough for Consent Fields.
4+
* https://gravitywiz.com/documentation/gravity-forms-easy-passthrough/
5+
*
6+
* Instruction Video: https://www.loom.com/share/209126dc84ab483b9025c040f5adf450
7+
*
8+
* Passes through the value of a consent field from the source form to the target form.
9+
*/
10+
add_filter( 'gform_pre_render', function( $form ) {
11+
// Update to the source and target consent field IDs and target form ID.
12+
$source_consent_field_id = '4';
13+
$target_consent_field_id = '4';
14+
$target_form_id = '80';
15+
16+
if ( $form['id'] != $target_form_id ) {
17+
return $form;
18+
}
19+
20+
if ( rgget( 'ep_token' ) && is_callable( 'gp_easy_passthrough' ) ) {
21+
$token = rgget( 'ep_token' );
22+
$entry = $token ? gp_easy_passthrough()->get_entry_for_token( $token ) : array();
23+
24+
if ( empty( $entry ) ) {
25+
return $form;
26+
}
27+
28+
foreach ( $form['fields'] as $field ) {
29+
if ( $field->type == 'consent' && $field->id == $target_consent_field_id && rgar( $entry, $source_consent_field_id . '.1' ) == '1' ) {
30+
?>
31+
<script type="text/javascript">
32+
document.addEventListener( 'DOMContentLoaded', function() {
33+
var consentCheckbox = document.getElementById( 'input_<?php echo $form['id']; ?>_<?php echo $field->id; ?>_1' );
34+
35+
if ( consentCheckbox ) {
36+
consentCheckbox.checked = true;
37+
}
38+
});
39+
</script>
40+
<?php
41+
}
42+
}
43+
}
44+
return $form;
45+
}, 12, 1 );

0 commit comments

Comments
 (0)