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.

gform_field_value for specific form?

  1. sascha
    Member

    Hi there,

    Can the gform_field_value be made/used, so that it is (or can be) form specific?

    Let's say I have more than one form that uses the same parameter name i.e "my_parameter". As far as I understand that filter at the moment will populate the "my_parameter" on all forms with the same values. What if I want to use the same parameter name, but have on different forms different values pre-populated? Is that possible?

    Posted 10 years ago on Tuesday January 10, 2012 | Permalink
  2. Yes. But you need to share more information with us. Give us an example of how you expect this to work, and we will help you with the code.

    Posted 10 years ago on Tuesday January 10, 2012 | Permalink
  3. sascha
    Member

    Let's say I have form 1 that uses "first_name" and form 2 that uses "first_name" as the parameter name. On form 1 I want to populate this with the info from the BP xprofile field on form 2 I want to populate it from the WP profile field.

    Of course I could use bp_first_name and wp_first_name, but just wanted to know if it is possible to keep the same parameter name and use gform_field_value for a specific form.

    Posted 10 years ago on Tuesday January 10, 2012 | Permalink
  4. In general, I think you might have to combine two filters or hooks to make this happen. You will need to put this filter, to populate the name, inside a function that checks for the form ID, since the form ID is not used in gform_field_values.

    You might do something like this (untested):

    <?php
    add_filter("gform_pre_render", "populate_name");
    function populate_name($form){
        // for form 5
        if($form["id"] == 5) {
            add_filter("gform_field_value_first_name", "read_name");
            function read_name($value) {
                // read your username here into the $username variable
                return $username;
            } // end read_name
    
        // for form 1
        if($form["id"] == 1) {
            add_filter("gform_field_value_first_name", "read_name");
            function read_name($value) {
                // read your username here into the $username variable
                return $username;
            } // end read_name
        } // end gform_field_value_first_name
        return $form;
    } // end gform_pre_render

    That would be a high level overview of how to do it.

    http://www.gravityhelp.com/documentation/page/Gform_field_value_$parameter_name

    Posted 10 years ago on Wednesday January 11, 2012 | Permalink
  5. sascha
    Member

    Great! Thanks, will try this. Would it make sense to add that ability to call gform_field_values with an ID? Like some of your other hooks/filters? gform_field_values_1, gform_field_values_2 or gform_field_values for all?

    Posted 10 years ago on Saturday January 14, 2012 | Permalink
  6. +1 to having the form ID available in some way to the field_values hook—I feel like wanting to do specific things based on the form would be a pretty common use-case

    Posted 10 years ago on Thursday January 19, 2012 | Permalink