- Creating and Publishing a Form
- Conversational Form
- Create Multi Step Forms In WordPress
- Using Calculations in SureForms: A Step-by-Step Guide
- Calculation Formula Guide
- SureForms Login Block – Step-by-Step Guide
- SureForms Registration Block – Step-by-Step Guide
- SureForms – PDF Generation Feature
- GDPR Compliant Forms
- Create WordPress Forms With Conditional Logic
- Adjust Form Notification Emails
- Form Confirmation
- Entries Management Feature Guide
- How to Add Query Parameters to Form Redirects
- How to Fetch Query Parameters from URL
- Set the “From Email” in SureForms
- Setting Up “Reply-To” Email Using Form Input Tags – SureForms
- Restrict Form Entries in SureForms
- Form Scheduling in SureForms
- Conditional Confirmations in SureForms
- SureForms Integration with ActiveCampaign
- SureForms Integration with AgileCRM
- SureForms Integration with Airtable
- SureForms Integration with LatePoint
- SureForms Integration with FluentCRM
- Connect SureForms To Zapier
- Automate WordPress Forms with the Custom App Builder
- SureForms Integration with Telegram
- SureForms Integration with Breeze
- SureForms Integration with Brevo
- Unable to Upload SureForms ZIP: File Unzipped On Download
- Browser Support for SureForms
- Not Getting Update Notifications
- How To Rollback to Previous SureForms Versions
- Publishing Failed: Invalid JSON Response
- Troubleshooting Email Sending In SureForms
- SureForm Submissions Marked as Spam – How to Fix
- API Request Failed – Nonce Verification Error
- Fixing the “Destination folder already exists” Error When Installing SureForms
- How to Set Up SureForms with Caching Plugins
- srfm_enable_redirect_activation
- sureforms_plugin_action_links
- srfm_quick_sidebar_allowed_blocks
- srfm_integrated_plugins
- srfm_suretriggers_integration_data_filter
- srfm_form_submit_response
- srfm_enable_gutenberg_post_types
- srfm_languages_directory
- srfm_form_template
- srfm_disable_nps_survey
Filter: srfm_block_field_markup
Description
The srfm_block_field_markup filter allows you to modify the final HTML markup of a form field before it is rendered on the page. This is a powerful filter that can be used to make significant changes to a field’s appearance or functionality, including adding, removing, or changing dropdown options.
The filter is applied at the end of the markup() method in the SRFM\Inc\Fields classes (e.g., Dropdown_Markup, Text_Markup, etc.).
Parameters
markup(string): The complete HTML markup for the field.args(array): An array of arguments containing details about the field:slug(string): The field type slug (e.g.,dropdown,text).field_name(string): The generated name of the field.is_editing(bool): Whether the field is being rendered in the entry editor.attributes(array): An array of the block’s attributes, including theblock_id.
Return
- (string): The modified HTML markup.
Example: Adding a New Option to a Dropdown
This example shows how to use the srfm_block_field_markup filter to add a new “Student” option to a specific dropdown field.
phpCopyEditadd_filter( 'srfm_block_field_markup', 'add_custom_dropdown_option', 10, 2 );
/**
* Adds a new "Student" option to a specific dropdown field.
*
* @param string $markup The original HTML markup of the field.
* @param array $args An array of arguments about the field.
* @return string The modified HTML markup.
*/
function add_custom_dropdown_option( $markup, $args ) {
// Target a specific dropdown field. Replace 'your-block-id' with the actual block_id.
$target_block_id = 'your-block-id';
// Ensure we are modifying the correct dropdown field and not in the admin entry editor.
if ( 'dropdown' === $args['slug'] && isset( $args['attributes']['block_id'] ) && $target_block_id === $args['attributes']['block_id'] && ! $args['is_editing'] ) {
// Define the new option to be added.
$new_option = '<option value="Student">Student</option>';
// Find the placeholder option to insert the new option after it.
$placeholder_text = ! empty( $args['attributes']['placeholder'] ) ? $args['attributes']['placeholder'] : 'Select an option';
$placeholder_tag = '<option class="srfm-dropdown-placeholder" value="" disabled selected>' . esc_html( $placeholder_text ) . '</option>';
// Insert the new option after the placeholder.
$markup = str_replace( $placeholder_tag, $placeholder_tag . $new_option, $markup );
}
return $markup;
}
Replace
'your-block-id'with the actual block ID of the dropdown field. You can find this ID in the block’s Advanced settings in the editor.
Filter: srfm_field_config (For JavaScript)
As stated previously, srfm_field_config cannot change dropdown options, but it is useful for other things.
Description
The srfm_field_config filter allows you to add custom configuration data to a form field’s data-field-config attribute. This attribute is rendered in the field’s HTML markup and can be accessed by JavaScript on the frontend. It is useful for custom client-side logic, such as calculations, validations, or conditional logic.
Parameters
field_config(array): The field configuration array. This is initially an empty array that you can add your custom data to.attributes(array): An array of the block’s attributes.
Return
- (array): The modified field configuration array.
We don't respond to the article feedback, we use it to improve our support content.