Description

Action fires before the form is displayed to determine position of certain form elements such as labels.

Parameters

$fields
array Sanitized entry field values/properties.
$form_data
array Form settings/data.

Source

wpforms/includes/class-frontend.php

More Information

The wpforms_display_field_after action fires before the form is displayed. This action can be used to move attributes of the form around such as form field labels.

Examples

It’s important to note that when using this action to reposition the field label below the form field, you must first also use the wpforms_display_field_before action to first remove the label from being displayed before the form field so that you can call the action to reposition the label after the form field.

/**
 * Action fires before the form is displayed to determine position of certain form elements such as labels.
 *
 * @link   https://wpforms.com/developers/wpforms_display_field_after/
 * 
 * @param  array    $fields      Sanitized entry field values/properties.
 * @param  array    $form_data   Form settings/data.
 *
 * @return array
 */


/* First remove the label from appearing above the form field for form 1289 */

function wpf_dev_display_field_before( $field, $form_data ) {
 
if ( absint( $form_data['id'] ) !== 1289 ) {
return;
}
    remove_action( 'wpforms_display_field_before', array( wpforms()->frontend, 'field_label' ), 15 );
}
 
add_action( 'wpforms_display_field_before', 'wpf_dev_display_field_before', 10, 2 );

/* Now position the label to appear below the form field for form 1289 */

function wpf_dev_display_field_after( $field, $form_data ) {
if ( absint( $form_data['id'] ) !== 1289 ) {
return;
}
 
    wpforms()->frontend->field_label( $field, $form_data );
}
 
add_action( 'wpforms_display_field_after', 'wpf_dev_display_field_after', 1, 2 );


Snippet References: