Description

The wpforms_frontend_output fires before a form is displayed on the site’s frontend and inside the HTML form container. It will only fire if the form exists and contains fields.

Parameters

$form_data
(array) Processed form settings/data, prepared to be used later.
$form
(WP_Post) Form post type.

Source

wpforms/src/Frontend/Frontend.php

More Information

While wpforms_frontend_output only fires for valid non-empty forms, it executes early on in the output rendering process. However, what you place with this action will be displayed inside the HTML form container.

An alternate action to consider is wpforms_frontend_output_before, as it functions similarly, except it will be outside of the HTML form container.

Examples

In our example, we have a form that will be taken down on Christmas day. We want to display a message above the form that will calculate today’s date less Christmas day and give the user a count of how many days are left to submit the form.

/**
 * Output something before your form(s).
 * 
 * @link  https://wpforms.com/developers/wpforms_frontend_output/
 *
 * @param array   $form_data Form data and settings.
 * @param object  $form      Form post type.
 */

function wpf_dev_frontend_output( $form_data, $form ) {

    // Optional, you can limit to specific forms. Below, we restrict output to
    // form #898.
    if ( absint( $form_data[ 'id' ] ) !== 898 ) {
    return;
    }

	// Set the PHP timezone
	date_default_timezone_set( 'America/New_York' );

	// Set the variable to Christmas day
	$christmasDay = strtotime( 'December 25' );

	// Get the current date
	$time = time();

	// Calculate how many days from today's date to Christmas day	
	$days = ceil(($christmasDay - $time)/60/60/24);

	echo '<div class="countdown_wrapper"> <p>' . __( 'This contest closes on <strong>12/25/2024</strong>, enter now! There are only <strong>', 'text-domain' ) . $days . __( '</strong> days left to enter!', 'text-domain' ) . '</p></div>';
	
}

add_action( 'wpforms_frontend_output', 'wpf_dev_frontend_output', 10, 2 );

Article Reference: How to Display Remaining Entry Limit Number