|
/ Documentation /Developer Documentation/Action Hooks/ How to Change Checkbox Submission Value from “On” to “Yes” or Custom Text in SureForms

How to Change Checkbox Submission Value from “On” to “Yes” or Custom Text in SureForms

By default, when a user selects a checkbox in a SureForm, the submitted value appears as “on”. If you want to change this value to something more user-friendly like “Yes” or localize it based on the site language, you can easily do this using a filter.

PHP
add_filter('srfm_before_prepare_submission_data', function($submission_data) {
    foreach ($submission_data as $key => $value) {
        if (strpos($key, 'srfm-checkbox') !== false || strpos($key, 'srfm-gdpr') !== false) {
            $submission_data[$key] = ($value === "on") ? __( "Yes", "sureforms") : __( "No", "sureforms");
        }
    }
    return $submission_data;
});

How it works:

  • This filter runs before form data is saved or sent.
  • It checks if the submitted field is a checkbox.
  • If selected, it replaces “on” with “Yes”.
  • The __() function ensures it’s translation-ready if you’re building a multilingual site.

Customize for your language or terms:

You can modify the “Yes” to fit your site’s tone or language. For example:

PHP
__( "Ja", "sureforms") // German
__( "Oui", "sureforms") // French
__( "Sim", "sureforms") // Portuguese

To ensure the custom text shows correctly in email notifications or webhook data, make sure to place this code in your child theme’s functions.php file or use a plugin like Code Snippets to safely insert custom code. Using a code snippet plugin is recommended for easier management and to ensure the code remains active even if you switch themes.

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
On this page
Scroll to Top