Support

Account

Home Forums General Issues Populate Gravity form fields with ACF subfield values based on dropdown select Reply To: Populate Gravity form fields with ACF subfield values based on dropdown select

  • Thanks for your input. I also read the documentation on https://www.advancedcustomfields.com/resources/repeater/ and try to match the subfield values with the code below, but still doesn’t work out.

    add_action( 'gform_pre_submission_1', 'gf_get_corresponding_course_enddate' );
    function gf_get_corresponding_course_enddate( $form ) {
    	$post_id = get_query_var('course'); //post id from url parameter
    	$startdate = rgpost( 'input_34' ); //value from Gravity forms field with id=34
    	$rows = get_field('course_info'); //repeater field is called course_info
    		if( $rows ) {
       		$first_row = $rows[0];
        		$first_row_title = $first_row['startdate']; // repeater subfield is called startdate
    		$second_row = $rows[1];
    		$second_row_title = $second_row['startdate'];
    		}
        	if ($first_row_title == $startdate) { // if gravity forms field input value equals startdate subfield value of the first row
    		$_POST['input_40'] = get_post_meta($post_id, 'stap_0_location', true); // add location subfield value of the first row to the gravity forms text field with id=40
    	} else if ($second_row_title == $startdate) {
    		$_POST['input_40'] = get_post_meta($post_id, 'stap_1_location', true);
    // add location subfield value of the second row to the gravity forms text field with id=40
    	} else {
    		$_POST['input_40'] = 'location not known';
    	}
    }

    Unfortunately every time the result is ‘location not known’, even if the Gravity form input value equals the startdate subfield value…