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.

Dynamically populate fields with custom fields from another DB?

  1. I understand how to use the built-in WordPress fields to prepopulate a form - see the "Ordered By" section here where that's working fine for first name, last name and email:

    http://www.cvsinc.net/online-orders/

    However I'm using aMember for user registration and membership management. Users can't see this GF order form unless they're logged in as aMember registered users within WordPress. What I need to do is prepopulate the custom fields in the "Ordered By" section using aMember user data.

    Can someone point me in the right direction?

    Posted 12 years ago on Thursday June 9, 2011 | Permalink
  2. Here's where I started - I have a field for aMember called company_name. Note that company_name is *not* in the WP db - this is where my problem is, or part of it. I made the parameter name in the 'allow field to be populate dynamically' box 'company.'

    // populate the field with "company" as the population parameter with the "company_name" of the current user
    add_filter('gform_field_value_company', create_function("", '$value = populate_usermeta(\'company_name\'); return $value;' ));
    Posted 12 years ago on Thursday June 9, 2011 | Permalink
  3. Getting closer - the amProtect plugin developer Ken Gary is helping me with this, not quite there yet. amProtect links aMember and WP so WP pages can be protected for aMember customers.

    Posted 12 years ago on Thursday June 9, 2011 | Permalink
  4. On my site dynamic fields are acting a bit strange.

    If I add this code to my functions

    add_filter("gform_field_value_company", "populate_company");
    	function populate_company($value){ return "Kencinnus"; }
    
    	add_filter('gform_field_value_email', 'populate_post_email');
    
    	function populate_post_email($value)
    	{
    
    		global $post;
    		$author_email = get_the_author_meta('email', $post->post_author);
    		return $author_email;
    	}

    And I create a form where there is an email field that has the allow dynamic field population enabled with parameter email, and a company field that has the allow dynamic field population with parameter company....nothing happens.

    But, if I add a query string to the contact form page like this /contact?company=whatever, then BOTH fields get populated with the values from the filters...not the value in the query string. And it does not matter if I use the ?email=whatever or ?company=whatever and it does not matter what whatever is.

    So why is it not working unless I have a query string on the contact form page? Am I missing some part of the process?

    Posted 12 years ago on Thursday June 9, 2011 | Permalink
  5. The populate from the query string because dynamic population is working properly, dynamic population works via either the query string or via PHP. So the problem is going to be with your PHP code.

    Make sure you review your code and compare with what is described in this tutorial:

    http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population

    Posted 12 years ago on Thursday June 9, 2011 | Permalink
  6. I have reviewed my code. Nothing is wrong with it. I'm pretty sure. You saw the code in my post above. Is there anything wrong with it? Is there supposed to be more than that?

    In fact, when I DO put a query string on, the value that gets put into the form is from the code...not the query string.

    That's the weird part.

    The code IS working, but ONLY if a query string is present.

    The question is why?

    Posted 12 years ago on Friday June 10, 2011 | Permalink
  7. Great! You know how it goes. I was going to show you the difference...and it's working properly now. Weird.

    Posted 12 years ago on Friday June 10, 2011 | Permalink
  8. So I've updated my amProtect Wordpress/aMember integration plugin to support the dynamic fields in Gravity Forms.

    it takes care of all of the add_filter() stuff behind the scenes for every field in the aMember member record.

    All you have to do is edit the field in your Gravity Form in the advanced tab by checking the box next to "Allow field to be populated dynamically" and then entering the aMember field name as the parameter.

    If you are not really familiar with the innards of the aMember member record it could be hard to figure out what to use. But they are the same things that are documented in the amProtect plugin for shortcodes that you can use within posts. So you can just edit a post and look at the amProtect section for the examples of what is available for personalization shortcodes.

    You have all of the normal fields that are off-the-shelf with aMember such as name_f, name_l, email, street, city, zip, country, etc. Even fields like login,password if you need them.

    And if you have created any additional custom fields in aMember then those are available too.

    For example if you created a field with a field id of "company" then you can just enter "company" into the Gravity Forms parameter for the dynamic field. If it was "phone" you can enter "phone" or if it is "company_name" you can enter "company_name". It will be there.

    Hope this helps everyone! It was a fun thing to figure out how to make happen.

    Posted 12 years ago on Friday June 10, 2011 | Permalink
  9. Awesome work, Ken! Thank you so much - this works beautifully.

    Posted 12 years ago on Friday June 10, 2011 | Permalink

This topic has been resolved and has been closed to new replies.