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.

How do you dynamically populate a form field with meta data from a custom field?

  1. Carson
    Member

    I tried adding this to my theme functions...but it did not work:

    add_filter("gform_field_value_hidden_field", "populate_hidden_field");

    function populate_hidden_field(){

    return get_post_meta($post->ID, custom_field_key, true);

    }

    Posted 13 years ago on Wednesday September 15, 2010 | Permalink
  2. Without looking at your site and seeing your form setup and custom field setup, there is no way to tell what is wrong. The Syntax looks correct.

    Is my login for your site still active? If so I can take a look and see how things are setup.

    Posted 13 years ago on Wednesday September 15, 2010 | Permalink
  3. Carson
    Member

    yup, you're login still works

    Posted 13 years ago on Wednesday September 15, 2010 | Permalink
  4. I'll need more details on what you are trying to do. Which form is it? Which hidden field? What is the custom field key and which posts already exist containing that custom field key? Be as detailed as possible.

    I've logged in but can't determine what you are trying to do or with what field so I need some more details to go on.

    Posted 13 years ago on Wednesday September 15, 2010 | Permalink
  5. Carson
    Member

    I emailed you.

    Posted 13 years ago on Wednesday September 15, 2010 | Permalink
  6. I have corrected the code in your theme, the post variable had to be declared as global. I updated your functions.php file and it's working now. Here is what the revised code looked like:

    add_filter("gform_field_value_service_city", "populate_service_city");
    function populate_service_city(){
      global $post;
      $service_city = get_post_meta($post->ID, company_description, true);
      return $service_city;
    }
    Posted 13 years ago on Thursday September 16, 2010 | Permalink