• Hello,

    I’m using ACF Pro to manage departure dates associated with a CPT called “Destinations”. Each destination has a repeater field containing a date picker.

    My goal is to dynamically display these dates in a <select> field within Contact Form 7, based on the currently viewed destination.?? My Setup:

    • CPT: destinations
    • ACF Repeater Field: date__repeater
    • Date Field within the Repeater: date__repeater-item
    • CF7 Form: contains a <select> field where I want to inject the repeater field dates for the current destination.

    ?? Issues I’m Facing:

    1. CF7 does not natively support repeater fields.
    2. I need the best method to retrieve and dynamically display these dates.

    Can you advise me on the best approach to integrate these ACF fields into Contact Form 7 without complex PHP solutions?

    Thank you in advance for your help!

    Best regards,

Viewing 1 replies (of 1 total)
  • Plugin Author Tessa (they/them), AuRise Creative

    (@tessawatkinsllc)

    Hi @lucasdabout

    I’m not sure the answer you’re looking for won’t be “complex PHP” but I hope the PHP snippets I provide will be easy to understand.

    While CF7 cannot support repeater fields, DTX can! You’ll need a custom shortcode to access the ACF data and return them as options for your select field. So something like this (since you didn’t mention what the field name is for your repeater or its subfield, the example is using departure_dates and departure_date):

    /**
    * Get ACF Repeater Options for DTX Select
    *
    * @return string JSON encoded string of ACF repeater options
    */
    function lucasdabout_cf7dtx_departures()
    {
    // Define my options array
    $options = array();

    if(!function_exists('have_rows')) {
    return ''; // Bail in case ACF is disabled
    }

    // Get my departure dates, see https://www.advancedcustomfields.com/resources/repeater/
    if(have_rows('departure_dates')) {

    // Add dates to the $options array
    while( have_rows('departure_dates') ) {
    $date = get_sub_field('departure_date');

    // Use the formatted date value as the option's value and label
    $options[$date] = $date;
    }

    }

    // Return options as JSON encoded string
    return json_encode($options);
    }
    add_shortcode('lucasdabout_cf7dtx_departures', 'lucasdabout_cf7dtx_departures');

    And then in your form template, use this to create the select field:

    [dynamic_select* departure_date include_blank use_label_element dtx_hide_blank dtx_disable_blank placeholder:Select%20a%20departure%20date "lucasdabout_cf7dtx_departures"]

    Bonus, I added attributes to make the select field required with placeholder text “Select a departure date”. More info on those attributes here.

    Hope that helps!

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.