ri_pre_populate_the_form

The Gravity Forms Data Persistence Add-On Reloaded ri pre populate the form function.

Description

ri_pre_populate_the_form( $form, $ajax ); 

Parameters (2)

0. $form
The form.
1. $ajax
The ajax.

Usage

  1. if ( !function_exists( 'ri_pre_populate_the_form' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'gravity-forms-data-persistence-add-on-reloaded/gravity-forms-data-persistence-add-on-reloaded.php'; 
  3.  
  4. // The form. 
  5. $form = null; 
  6.  
  7. // The ajax. 
  8. $ajax = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = ri_pre_populate_the_form($form, $ajax); 
  12.  

Defined (1)

The function is defined in the following location(s).

/gravity-forms-data-persistence-add-on-reloaded.php  
  1. function ri_pre_populate_the_form( $form, $ajax ) { 
  2. if ( gfdp_is_persistent( $form ) ) { 
  3. $form['cssClass'] .= ' gfdp'; 
  4. $current_page = GFFormDisplay::get_current_page( $form["id"] ); 
  5. if ( $current_page == 1 ) { 
  6. if ($data = get_transient( ri_gfdp_getFormTransientKeyForGF( $form ) ) ) { 
  7. $_POST = json_decode( $data, true ); 
  8. foreach ( $form['fields'] as $field ) { 
  9. if ( rgar( $field, "allowsPrepopulate" ) ) { 
  10. if ( is_array( rgar( $field, "inputs" ) ) ) { 
  11. foreach ( $field["inputs"] as $input ) { 
  12. if ( ! empty( $_GET[ $input['name'] ] ) ) { 
  13. $_POST[ 'input_' . str_replace( '.', '_', $input['id'] ) ] = $_GET[ $input['name'] ]; 
  14. } else { 
  15. if ( ! empty( $_GET[ $field['inputName'] ] ) ) { 
  16. $_POST[ 'input_' . $field['id'] ] = $_GET[ $field['inputName'] ]; 
  17.  
  18. return $form;