Skip to content

Commit 9308a6b

Browse files
committed
gpep-passthrough-consent-field.php: Added snippet for easy passthrough on Consent Field.
1 parent a9113c6 commit 9308a6b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

gp-easy-passthrough/gpep-passthrough-consent-field.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Passes through the value of a consent field from the source form to the target form.
99
*/
1010
add_filter( 'gform_pre_render', function( $form ) {
11-
// Update to the source and target consent field IDs and target form ID.
11+
// Update to the source and target consent field IDs and target form ID.
1212
$source_consent_field_id = '4';
1313
$target_consent_field_id = '4';
1414
$target_form_id = '80';
@@ -18,14 +18,19 @@
1818
}
1919

2020
if ( rgget( 'ep_token' ) && is_callable( 'gp_easy_passthrough' ) ) {
21-
$entry = gp_easy_passthrough()->get_entry_for_token( rgget( 'ep_token' ) );
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+
}
2227

2328
foreach ( $form['fields'] as $field ) {
24-
if ( $field->type == 'consent' && $field->id == $target_consent_field_id && $entry[ $source_consent_field_id . '.1' ] == '1' ) {
29+
if ( $field->type == 'consent' && $field->id == $target_consent_field_id && rgar( $entry, $source_consent_field_id . '.1' ) == '1' ) {
2530
?>
2631
<script type="text/javascript">
2732
document.addEventListener( 'DOMContentLoaded', function() {
28-
var consentCheckbox = document.querySelector( 'input[name="input_<?php echo $field->id; ?>.1"] ');
33+
var consentCheckbox = document.getElementById( 'input_<?php echo $form['id']; ?>_<?php echo $field->id; ?>_1' );
2934

3035
if ( consentCheckbox ) {
3136
consentCheckbox.checked = true;

0 commit comments

Comments
 (0)