Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Render persistence data before form output changed to work with populated fields.
```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
You can’t perform that action at this time.