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.

Option/function to return a more complex form data structure

  1. dnb
    Member

    Hi-
    This is related to my post here about helper functions for GF. On a recent project, I needed to use the entry object returned by gform_after_submission() to retrieve all of the responses in a checkbox field. As far as I know, the only way to do this is to do a linear walk over the keys in the entry object, doing a string match for the ID of that field as a prefix (i.e. if the field ID is 3, you look for 3.1, 3.2, 3.3, etc.).

    It would be really great if there was a way to get back an entry object that wasn't just a flat array. Using the example above, something like:

    $entry[3] = [ {3.1's value}, {3.2's value}, ... {3.x's value} ];

    would be awfully spiffy and make the retrieval of all of the values returned from a multi-valued field much easier.

    If you want to get really fancy, it would also be great if fields could also be referenced by name, so that one could do:

    $entry['checkbox_field_name'] = [{value1}, {value2}, {value3}...{valueX}] ;

    If there were two fields with the same name, you would suffix the name with the field ID, as in:

    $entry['checkbox_field_name_3'] = [ {value1}, {value2}, {value3} ... ] ;

    The rationale for this request is code that says:

    $entry['checkbox_field_name']

    is much easier to grok than:

    $entry['3']

    It also seems a little less fragile to me, since if that field is no longer #3 for some reason, the code doesn't break.

    Thanks for considering this idea!

    -- dNb

    Posted 12 years ago on Sunday January 8, 2012 | Permalink
  2. I forwarded this topic to one of the developers to see if we can get some feedback for you. Thanks for your patience.

    Posted 12 years ago on Monday January 9, 2012 | Permalink
  3. dnb
    Member

    Super, thanks!
    -- dNb

    P.S. There's no rush (I know one of them is sunning himself as we speak).

    Posted 12 years ago on Monday January 9, 2012 | Permalink
  4. Uh oh! Busted.

    These are some good ideas and I do agree that these changes would make the entry object easier to use. My question is how do we make it backwards compatible? Lots of people are already relying on the entry object in this format. Also, where would you get the field name from to use it as an index?
    Thanks for the suggestions.

    Posted 12 years ago on Tuesday January 10, 2012 | Permalink
  5. I found it easier to do by using the form object and adding code to flip through the entry object when it comes across a checkbox field. It's easy enough that I would think it would be a waste of time and too much trouble for backward compatibility to change the actual entry object.

    Posted 12 years ago on Thursday January 12, 2012 | Permalink
  6. Thanks for your thoughts Ben.

    Posted 12 years ago on Tuesday January 17, 2012 | Permalink
  7. dnb
    Member

    Hi Alex-
    Sorry for being so slow to respond to your reply (didn't get an email notification). Let me see if I can answer your questions:

    1) backward compatibility but providing a non-flat entry object when requested - I appreciate that you are trying to preserve this:

    There are a number of ways to handle this. A few ideas:

    • Some APIs (like the old LDAP C SDK) provide additional calls that return extended versions of an object, so you could have explicit hooks that did it ("gform_after_submission_ex()").
    • Some have you pass a flag into the call to request the enhanced version.
    • Some provide helper methods (get_all_values_ex()) that you can call on/from the object.
    • Some sort of global flag (my least favorite idea, where you say $GF::ObjectVersion = 2).

    2) where to get the field name if indexing by field names: I'm suggesting you get it from the 'label' (or 'adminLabel' if set) form field value.

    ... or, see my post about a library of helper functions. A helper function that takes in a flat entry object but returns one that is easier to work with would also be viable (albeit a bit of a performance hit). You could imagine something like:

    $better_entry = make_nice_entry($entry); # bad name, I know
    $better_entry['colorcheckbox'] would now be a list ('red', 'blue') based on the form choice.

    In regard to Ben's response: Ben, could you post a snippet of code? I'm not sure I understand what you are suggesting and why having an entry object that was easier to work with would be a bad thing if backward compatibility could exist for some number of versions.

    Posted 12 years ago on Tuesday January 24, 2012 | Permalink