Support

Account

Home Forums General Issues How to create dynamic select in ACF and pass to CF7?

Solved

How to create dynamic select in ACF and pass to CF7?

  • Hi there, I was looking for a simple solution to pass a set of ACF custom fields values of a sub_field (coming from a repeater field) and pass them to a custom select of CF7 (dynamically populated). I tried looking elsewhere on stackexchange, here on documentation and google, but I can’t find an exhaustive solution, realistically for my limited programming knowledge.
    I hope in your answer and in a future release of Custom Dynamic Fields for ACF 🙂

  • I found a solution! I hope it will be useful for someone else in future:

    function add_date_to_cf7() {
    
    	$output = "<select name='date_corso' id='date_corso' onchange='document.getElementById(\"date_corso\").value=this.value;'><option></option>";
    
    	if( have_rows('gruppo_date') ) {
            while( have_rows('gruppo_date') ) {
                the_row();
               
               $output .= '<option value="'.get_sub_field('intervallo_date_corso').'">' .get_sub_field('intervallo_date_corso'). '</option>';
    
            }
        }
    	$output .= "</select>";
    
    	return $output;
    }
    
    wpcf7_add_shortcode('date_corso', 'add_date_to_cf7', true);
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to create dynamic select in ACF and pass to CF7?’ is closed to new replies.