Skip to content

Commit 1b369f2

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

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
add_action( 'wp_ajax_gpnf_session', 'gw_gpnf_disable_session', 9 );
1616
add_action( 'wp_ajax_nopriv_gpnf_session', 'gw_gpnf_disable_session', 9 );
1717
function gw_gpnf_disable_session() {
18+
// Store request
19+
$request = $_REQUEST['request'] ?: array();
20+
$form_id = $_REQUEST['form_id'];
21+
setcookie( "{$form_id}-request", json_encode( $request ), 0, COOKIEPATH, COOKIE_DOMAIN, is_ssl() );
1822

1923
remove_action( 'wp_ajax_gpnf_session', array( gp_nested_forms(), 'ajax_session' ) );
2024
remove_action( 'wp_ajax_nopriv_gpnf_session', array( gp_nested_forms(), 'ajax_session' ) );
@@ -23,7 +27,23 @@ function gw_gpnf_disable_session() {
2327
// and as a security precaution to prevent malicious users from creating artificial session cookies.
2428
$session = new GPNF_Session( rgpost( 'form_id' ) );
2529
$session->delete_cookie();
30+
}
31+
32+
// Retrieve the stored request and populate field value.
33+
add_action( 'wp_ajax_gpnf_refresh_markup', 'populate_field_from_request' );
34+
add_action( 'wp_ajax_nopriv_gpnf_refresh_markup', 'populate_field_from_request' );
35+
function populate_field_from_request() {
36+
$form_id = $_REQUEST['gpnf_parent_form_id'];
37+
$request = json_decode( stripslashes( $_COOKIE[ "{$form_id}-request" ] ), true );
38+
39+
add_filter( 'gform_field_value', function( $value, $field, $name ) use ( $request ) {
40+
$_value = rgar( $request, $name );
41+
if ( $_value ) {
42+
$value = $_value;
43+
}
2644

45+
return $value;
46+
}, 10, 3 );
2747
}
2848

2949
add_filter( 'gpnf_can_user_edit_entry', function( $can_user_edit_entry, $entry, $current_user ) {

0 commit comments

Comments
 (0)