fluentform_rendering_field_html_{dynamic}
> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filters the HTML output for a specific dynamic field before it's rendered in Fluent Forms.
add_filter( 'fluentform_rendering_field_html_{dynamic}', $callback, 10, 3 );
Description
This dynamic filter hook, `fluentform_rendering_field_html_{dynamic}`, allows developers to modify the HTML output of specific Fluent Forms fields before they are rendered. Developers can intercept and alter the `$html`, `$data` (field attributes and settings), and `$form` objects. This is useful for custom styling, adding unique attributes, or conditionally changing field presentation. The `{dynamic}` part of the hook name changes based on the field's element type (e.g., `fluentform_rendering_field_html_text`).
Usage
add_filter( 'fluentform_rendering_field_html_{dynamic}', 'your_function_name', 10, 3 );
Parameters
-
$html(mixed) - This parameter contains the generated HTML for the field, which can be modified before it's outputted.
-
$data(mixed) - This parameter contains the HTML markup generated for the field.
-
$form(mixed) - This parameter contains data related to the specific form field being rendered, including its attributes and other relevant information.
Return Value
The filtered value.
Examples
/**
* Example filter to modify the HTML of a Fluent Forms text input field.
* This example appends a specific CSS class to all text input fields.
*/
add_filter( 'fluentform_rendering_field_html_input', function ( $html, $data, $form ) {
// Check if the field is a 'text' type input
if ( isset( $data['attributes']['type'] ) && $data['attributes']['type'] === 'text' ) {
// Add a custom class to the existing HTML.
// This assumes the $html variable contains the input tag and potentially other wrapper elements.
// A more robust approach might involve DOM manipulation if the structure is complex.
// For simplicity here, we'll assume adding a class to the main wrapper is sufficient.
$html = str_replace( 'ff-el-form-control', 'ff-el-form-control custom-text-input-class', $html );
}
return $html;
}, 10, 3 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/integrations/fluent-forms/class-ff-codes-field.php:130
function render( $data, $form ) {
$elementName = $data['element'];
$data = apply_filters( 'fluentform_rendering_field_data_' . $elementName, $data, $form );
if ( $tabIndex = FluentFormAppHelpersHelper::getNextTabIndex() ) {
$data['attributes']['tabindex'] = $tabIndex;
}
$data['attributes']['class'] = @trim( 'ff-el-form-control ' . $data['attributes']['class'] );
$data['attributes']['id'] = $this->makeElementId( $data, $form );
$elMarkup = $this->buildInputGroup( $data, $form );
$html = $this->buildElementMarkup( $elMarkup, $data, $form );
echo apply_filters( 'fluentform_rendering_field_html_' . $elementName, $html, $data, $form );
}