Forked from MikevHoenselaar/persistent_multipage_forms-reloaded.php
Created
January 20, 2017 23:05
-
-
Save mkormendy/094525d51237fe6963b39c7bdf58bc11 to your computer and use it in GitHub Desktop.
Render persistence data before form output changed to work with populated fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```php | |
// Render persistence data before form output | |
add_filter("gform_pre_render", "ri_pre_populate_the_form"); | |
function ri_pre_populate_the_form($form) { | |
if (gfdp_is_persistent($form)) { | |
$current_page = GFFormDisplay::get_current_page($form["id"]); | |
if ($current_page == 1) { | |
$option_key = ri_getFormOptionKeyForGF($form); | |
if (get_option($option_key)) { | |
$persistent_info = json_decode(get_option($option_key)); | |
//start new code | |
// For every field in form we have to check if populate is active, if so, grab inputName value (=$_GET value). If its not empty use that for default field value. | |
foreach ($form['fields'] as $_field) : | |
if (isset($_field['allowsPrepopulate']) && $_field['allowsPrepopulate']) : | |
$get_key = $_field->inputName; | |
if (isset($_GET[$get_key]) && !empty($get_key)) : | |
$field_id = ($_field->id) ? $_field->id : '' ; | |
if ($field_id && isset($persistent_info->{'input_'.$field_id})) : | |
$persistent_info->{'input_'.$field_id} = sanitize_text_field($_GET[$get_key]); | |
endif; | |
endif; | |
endif; | |
endforeach; | |
// end new code | |
$persistent_info = json_encode($persistent_info); | |
$_POST = json_decode($persistent_info, true); | |
} | |
} | |
} | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment