[Resolved] Dynamically populate Gravity Forms fields

Support Forums Support Dynamically populate Gravity Forms fields

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #128
    Brian McDaniel
    VEM User

    I have another customization question. We want to dynamically populate 3 Gravity Form fields with lists of all occurrences (specifically date and venue of each occurrence) for 3 separate events. In short, this is a package deal combining 3 separate events that, when purchased as a single ticket item, receive a discounted price. So when they purchase this package, they will need to select the date and location for each event in a select field on the form. I know this is possible using Gravity Forms filters (https://docs.gravityforms.com/using-dynamic-population/) but need to know how I would grab the list of occurrences from each of the 3 events. I realize this will require custom coding, but is it something relatively simple you could point me in the right direction toward?

    #129
    Brian McDaniel
    VEM User

    Here is another link with explanation of how to populate a GF drop down (select) field: https://docs.gravityforms.com/dynamically-populating-drop-down-fields/

    So I guess my question is regarding using get_posts to narrow down which event I am looking for specifically and then how to get the list of occurrences and print the date and venue for each occurrence within the GF filter that then populates the drop down.

    Thanks!

    #131
    Aaron Overton
    Lead Dev

    In your custom code (theme or plugin) you can create an instance of the VEM class and do a query. On it, you can set a context so that any filters you apply are specific to your custom code. (Context is an arbitrary string passed to our filters for that purpose.) Then you can filter the event where to just get you the specific event IDs you want. Finally, you can then retrieve the occurrences, which will also have their metadata already retrieved.

    $vem3 = new VentureEventManager3();
    $vem3->setContext('Iamtheawesome');
    // Do any other pre-retrieve settings you might need
    vem3->retrieveDates();
    $themThereDates = $vem3->getOccurrences();
    
    add_filter('vem_events_where', 'doWhereAdjust', 10, 3);
    function doWhereAdjust($where, $archives, $context) {
      if ($context != 'Iamtheawesome') return; // Restrict your filtering to just your context
      // Adjust the $where array to include your where clause for just the list of specific events
    
      return $newWhere;
    }

    I didn’t go test the above code snippet specifically, but I think it is right. I did check to make sure that the arguments on the filter are the correct number, order, and values. After the call to getOccurrences, $themThereDates should have all your dates for the three events and you can extra the relevant metadata from there.

    If you need more help getting this done, talk to Drew about some custom dev time and I can put it into a custom plugin for you.

    Blue skies,
    -Aaron

    #132
    Brian McDaniel
    VEM User

    Thanks, Aaron. While I somewhat understand what you’ve shown here, I am still a bit more lost than I’d like to be. I’ll reach out to Drew to see about a quote.

    #133
    Drew McManus
    Lead Dev

    Many thanks Brian, I’ll keep an eye out for your note.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.