PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Populating Address field on pre_render

  1. I'm trying to populate an address field with the billing address information from the current user's data. I do not know what I've done wrong. Also, if I check the box in the form to allow for dynamic population, how do I set up the hooks to get the data I want?

    I've created the following code:
    add_action("gform_pre_submission_2", "mwn_gform_pre_submission_2");

    function mwn_gform_pre_render_2($form){
    	$current_user = wp_get_current_user();
    	$user_data = get_user_meta($current_user->ID );
      foreach($form["fields"] as &$field)
      	switch($field["id"]){
    		case 27:
    			foreach($field["inputs"] as &$input) {
    				switch($input["id"]){
    						case 27.1:
    							$input["value"] = $user_data["billing_address_1"][0];
    							break;
    						case 27.2:
    							$input["value"] = $user_data["billing_address_2"][0];
    							break;
    						case 27.3:
    							$input["value"] = $user_data["billing_city"][0];
    							break;
    						case 27.4:
    							$input["value"] = $user_data["billing_state"][0];
    							break;
    						case 27.5:
    							$input["value"] = $user_data["billing_postcode"][0];
    							break;
    						default:
    							break;
    				}
    			}
    			break;
    		default:
    			break;
    	}
    
    	return $form;
    }
    Posted 5 years ago on Friday May 24, 2013 | Permalink
  2. acsnaterse
    Member

    Somebody has a clue? I'm dealing with the same problem here.

    Posted 5 years ago on Tuesday May 28, 2013 | Permalink
  3. Handling via priority support.

    Posted 5 years ago on Tuesday May 28, 2013 | Permalink
  4. acsnaterse
    Member

    That means a/the solution will not be posted here?

    I've solved it myself now by populating the $_GET array. That works, but, of course, is not ideal solution.

    Posted 5 years ago on Tuesday May 28, 2013 | Permalink
  5. Here was the dev recommendation:

    Instead of using gform_pre_render to do this, you will want to use this hook instead: http://www.gravityhelp.com/documentation/page/Gform_field_value_$parameter_name . The inputs for the address field do not store default data like you are trying to do. You will want to set your address field to allow dynamic population and enter parameter names like in this screen shot: http://grab.by/mYfi . Then you use those parameter names with the gform_field_value hook.

    There is some really good documentation on dynamic population on this page which links to other examples: http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population .

    Posted 5 years ago on Thursday May 30, 2013 | Permalink