Skip to content

Commit 222b8f6

Browse files
committed
gpnf-disable-sessions.php: Fixed an issue where nested form fields are not dynamically populated.
1 parent a793843 commit 222b8f6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

gp-nested-forms/gpnf-disable-sessions.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
add_action( 'wp_ajax_nopriv_gpnf_session', 'gw_gpnf_disable_session', 9 );
1717
function gw_gpnf_disable_session() {
1818

19+
// Store request
20+
$request = $_REQUEST['request'] ?: array();
21+
$form_id = $_REQUEST['form_id'];
22+
setcookie( "{$form_id}-request", json_encode( $request ), 0, COOKIEPATH, COOKIE_DOMAIN, is_ssl() );
23+
1924
remove_action( 'wp_ajax_gpnf_session', array( gp_nested_forms(), 'ajax_session' ) );
2025
remove_action( 'wp_ajax_nopriv_gpnf_session', array( gp_nested_forms(), 'ajax_session' ) );
2126

@@ -26,6 +31,23 @@ function gw_gpnf_disable_session() {
2631

2732
}
2833

34+
// Retrive the stored request and populate field value.
35+
add_action( 'wp_ajax_gpnf_refresh_markup', 'populate_field_from_request' );
36+
add_action( 'wp_ajax_nopriv_gpnf_refresh_markup', 'populate_field_from_request' );
37+
function populate_field_from_request() {
38+
$form_id = $_REQUEST['gpnf_parent_form_id'];
39+
$request = json_decode( stripslashes( $_COOKIE[ "{$form_id}-request" ] ), true );
40+
41+
add_filter( 'gform_field_value', function( $value, $field, $name ) use ( $request ) {
42+
$_value = rgars( $request, $name );
43+
if ( $_value ) {
44+
$value = $_value;
45+
}
46+
47+
return $value;
48+
}, 10, 3 );
49+
}
50+
2951
add_filter( 'gpnf_can_user_edit_entry', function( $can_user_edit_entry, $entry, $current_user ) {
3052
// Logged-in users can always edit their entries. Otherwise, only allow editing if the entry does not have a parent
3153
// and does not belong to a session.

0 commit comments

Comments
 (0)