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.

Is there a filter to replace existing fields with something else in form display

  1. I see that you have the "gform_field_choices_{$field["formId"]}" but am having trouble following the logic of how it works. What I'd like to do is take a field (I'm assuming that is something like 'field_1_3' for a checklist that I've set up for the form and replace all the inputs with a dynamic list I'm building from another place.

    Am I looking at the correct filter for this?

    Could I have a little bit of help in how to structure the add_filter to match where I need to place my new inputs?

    Posted 13 years ago on Thursday December 16, 2010 | Permalink
  2. Checkbox lists are problematic to dynamically populate. Because a checkbox isn't like a radio button or drop down where it's one field that consists of options. Each checkbox is actually an individual field.

    The way fields work in Gravity Forms they impact the Admin (available fields in the entry list, etc.). List items in radio buttons and drop downs do not because the individual items themselves are not a field.

    For that reason you aren't going to be able to populate them dynamically like you can a drop down or radio button.

    Posted 13 years ago on Thursday December 16, 2010 | Permalink
  3. Not sure I follow since the filter is included with the get_checkbox_choices() method then as found in the common.php file?

    Or maybe I didn't make myself clear enough? I want to use a form created in gravity forms for people to sign up for information on different items. The items will vary depending on data from an external application that I've hooked into using its api. So what I want to be able to do is "hook" into the form created in Gravity forms to output the relevant check box inputs from the info data from the other site.

    I couldn't find any "action" hooks in Gravity forms that would allow me to just inject the fields, however I was thinking that the filter I referenced might allow me to just "replace" the existing check boxes with my generated inputs. The code seems to indicate it's doable but my attempts at hooking into the filter have failed (I don't seem to be triggering the right call because I can't figure out what "{$field["formId"]}" should be.
    In other words, I'd just use the admin back end in Gravity forms to set the location of the check boxes but the actual fields will be replaced by the ones I generate and output using the filter. Does that make sense?

    Posted 13 years ago on Thursday December 16, 2010 | Permalink
  4. Hi Darren,

    What you need is the gform_pre_render filter hook. Using this hook you can update the form object (including the fields) of the form which is about to be generated.

    In addition to the example in the linked documentation, I've include a custom example that might shed some additional light on how the array containing your new checkbox options will need to be formatted.

    http://pastie.org/1384369

    After correctly formatting your array of new choices, you just assign that array back to the choices property of the correct field in the form object. Hope that helps!

    Posted 13 years ago on Friday December 17, 2010 | Permalink
  5. Thanks for taking the time to respond David (and do up the example code),
    That's closer to what I was wanting to do and would definitely work if I was just replacing existing checkboxes without adding or removing any new ones dynamically.

    However, I now realize (and understand what Carl was getting at) that I'm still going to have to work directly with the database because the result I have could result in a changing number of checkboxes and main fields generated. I can still build the form with the basic static fields that won't change but I'm using the methods from the RGFormsModel class to interact with the database when generating my form to insert the new fields as part of the $form object for my created form. I'll also have to populate changes across the other tables where $field data is linked in relationship (i.e. lead* tables) so I can maintain the entries records when the form changes.

    Thanks for your help guys and for such a straight forward database structure and VERY clean code base! You've made it easier to understand how things are working and for me to come up with a workable solution!

    Posted 13 years ago on Friday December 17, 2010 | Permalink

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