fluentform_rendering_field_data_{dynamic}
> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filters the data for a specific dynamic field before it's rendered in Fluent Forms.
add_filter( 'fluentform_rendering_field_data_{dynamic}', $callback, 10, 2 );
Description
Filters the data array before a Fluent Forms field is rendered. Use this dynamic hook, `fluentform_rendering_field_data_{elementName}`, to modify field attributes, values, or other rendering data. The `{elementName}` is replaced by the actual field type (e.g., `text`, `textarea`).
Usage
add_filter( 'fluentform_rendering_field_data_{dynamic}', 'your_function_name', 10, 2 );
Parameters
-
$data(mixed) - This parameter contains an array of data associated with the field being rendered, which can be modified by the hook.
-
$form(mixed) - This parameter contains the data associated with the current field being rendered.
Return Value
The filtered value.
Examples
/**
* Example: Modify the 'text' field's data before it's rendered.
* This hook allows you to alter the data array for specific field types.
* Here, we're adding a custom data attribute to text fields.
*/
add_filter( 'fluentform_rendering_field_data_text', function ( $data, $form ) {
// Add a custom data attribute for demonstration purposes.
// In a real scenario, you might check for specific form IDs or field settings.
$data['attributes']['data-custom-attribute'] = 'custom-value-' . $data['id'];
// You can also modify existing attributes or add new ones based on conditions.
if ( isset( $data['attributes']['placeholder'] ) && $data['attributes']['placeholder'] === 'Enter your name' ) {
$data['attributes']['data-user-greeting'] = 'Hello, welcome!';
}
// Always return the modified data.
return $data;
}, 10, 2 ); // 10 is the priority, 2 is the number of arguments accepted by the callback function.
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:118
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 );
}