File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 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+ $ entry = gp_easy_passthrough ()->get_entry_for_token ( rgget ( 'ep_token ' ) );
22+
23+ foreach ( $ form ['fields ' ] as $ field ) {
24+ if ( $ field ->type == 'consent ' && $ field ->id == $ target_consent_field_id && $ entry [ $ source_consent_field_id . '.1 ' ] == '1 ' ) {
25+ ?>
26+ <script type="text/javascript">
27+ document.addEventListener( 'DOMContentLoaded', function() {
28+ var consentCheckbox = document.querySelector( 'input[name="input_<?php echo $ field ->id ; ?> .1"] ');
29+
30+ if ( consentCheckbox ) {
31+ consentCheckbox.checked = true;
32+ }
33+ });
34+ </script>
35+ <?php
36+ }
37+ }
38+ }
39+ return $ form ;
40+ }, 12 , 1 );
You can’t perform that action at this time.
0 commit comments