Support

Account

Home Forums Add-ons Repeater Field How to map multiple Gravity Forms fields with ACF repeater oEmbed?

Solving

How to map multiple Gravity Forms fields with ACF repeater oEmbed?

  • Hello all,
    I need to create a post creating form with Gravity Forms, feeding the ACF i’ve created previously.
    Fields work fine, except in this case:
    in my form, there is a section where submitters have to choose from a dropdown how many Youtube video links they have to insert. Depending from the value they select, the corresponding rows fields appear. Lets suppose they choose 2 rows, so they have to insert 2 links to take into ACF field, my problem is:
    How can i feed an ACF oEmbed with multiple rows from the Gravity form submission? Because every time i try to map fields from the form with ACF repeater type with nested oEmbed lines, it doesn’t works.

    Thanks in advance to all

  • I believe you need to look at the gform_after_submission hook.

    You then use Gravity Forms rgar value.

    Perhaps, you could use repeater field and add the oEmbed field into that?

    <?php
    add_action( 'gform_after_submission', 'set_post_content', 10, 2 );
    function set_post_content( $entry, $form ) {
     
        //getting post
        $post = get_post( $entry['post_id'] );
     
        //change the 4 to your gravity form field number
        $number_of_posts = rgar( $entry, '1' );
    	
    	#add the row to the repeater
    	$row = array(
    		'field_5d9470467aab9'	=> $number_of_posts #this is your repeater subfield key
    	);
    	$i = add_row('field_5d946796a4fd7', $row, $post_id->ID); #this is the main repeater key
    	
    }

    Just an idea. You may need to play around with the concept!

  • Hi Jarvis,
    first of all, thank you for the support provided!
    My ACF field is already a Repeater with oEmbed subfields inside.
    I just want to pass data from post creation form to each subfield into repeater. As i can see from the code you posted, i should create a repeater field with only ONE oEmbed row inside, then i have to match form ID with ACF keys, and the code will add as many rows as many submission people will perform, right?

    I’ll try, thanks!

  • Yep

    So you can use the gform_after_submission as is or you can be more specific with the form ID:

    Applies to all forms.
    add_action( 'gform_after_submission', 'after_submission', 10, 2 );

    Applies to a specific form. In this case, form id 5.
    add_action( 'gform_after_submission_5', 'after_submission', 10, 2 );

    Change the 1 in the below to your Gravity Form field ID:
    $number_of_posts = rgar( $entry, '1' );

    Then switch the field key IDs:

    #add the row to the repeater
    	$row = array(
    		'field_5d9470467aab9'	=> $number_of_posts #this is your repeater subfield key
    	);
    	$i = add_row('field_5d946796a4fd7', $row, $post_id->ID); #this is the main repeater key
    	

    Without knowing the full ins and outs of your setup, that should help get you underway!

    You may need to tweak accordingly but fingers crossed!

  • Ok, this sounds clear and simple, but i just can’t find out subfields keys. I easily found the main field key, but not the same for subfields. Do i have to search in my DB? ACF version: latest, i think 5.1.1

  • No, you should be able to enable view field keys. This will show when your on the add/edit fields screen.

    Then click to edit your repeater field and it should then show the subfield keys

  • I’m sorry but i just can’t find out where to switch field key view on/off!
    These are my screens from ACF

  • I’ve managed to find out subfield keys printing a PHP of the main field in tools section of ACF!

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.