Gform_pre_replace_merge_tags

Hello
I’m using filter to format date in human readable string but I also need to get current form id inside this function, please see below, how is it possible to achieve it ? I have 2 different forms and I have to distinguish them for GFFormsModel::get_field( ); call.

thanks

add_filter( 'gform_pre_replace_merge_tags', function( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
    

	preg_match_all( '/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}/mi', $text, $matches, PREG_SET_ORDER );
	
		
		
		 $field = GFFormsModel::get_field( 3, 10 );


		if ( $field->get_input_type() !== 'date' ) {
			continue;
		}

		$i        = $match[0][0] === '{' ? 4 : 5;
		$modifier = rgar( array_map( 'trim', explode( ',', rgar( $match, $i ) ) ), 0 );
		if ( ! $modifier ) {
			continue;
		}

		$value = GFFormsModel::get_lead_field_value( $entry, $field );
		$value = $field->get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $value, $url_encode, $esc_html, $format, $nl2br );

		$format      = $field->dateFormat ? $field->dateFormat : 'mdy';
		$parsed_date = GFCommon::parse_date( $value, $format );

		$replace = date( $modifier, strtotime( sprintf( '%d-%d-%d', $parsed_date['year'], $parsed_date['month'], $parsed_date['day'] ) ) );
		
		$replace = convertFormDate($replace);

		$text = str_replace( $match[0], $replace, $text );
		
		$counter++;
		

	}


	return $text.$test;
	
}, 10, 7 );

The $entry and the $form objects are both available to this filter, so you can use either of these to get the form ID:

$form_id = $form['id'];

or

$form_id = rgar( $entry, 'form_id');

Let us know if you have any other questions.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.