Customizing the Form Locker Age Verification Message

Introduction

Would you like to customize the Form Locker age verification message that is displayed if the user age doesn’t meet the requirements? By default, when you set up your Form Locker addon settings to require age verification, a generic message is displayed if the user’s birthdate doesn’t meet the age required. Using a small PHP snippet you can easily customize this message and we’ll show you how!

Creating the form

To begin, we’ll create a new form and add our fields.

Once you’ve added your fields, go to the Settings tab and click Form Locker. Click the button to Enable verification and from the Type dropdown, select Age.

You can add your message that will be displayed before your form so that users understand why you’re asking for their birthdates.

create your form, add your fields and enable the age verification on the Form Locker tab

If you need any assistance with creating this type of form, please check out this documentation.

Adding the snippet

Now it’s time to add the snippet to your site. If you need help with how and where to add snippets, please check out this tutorial.

/**
 * Customize the Form Locker Verification Error Message
 *
 * @link https://wpforms.com/developers/customizing-the-form-locker-age-verification-message/
 */
 
function wpf_dev_form_locker_restriction_message( $message, $form_id, $form_data ) {

	// Only run on my form with ID = 2189
    if ( absint( $form_data[ 'id' ] ) !== 2189 ) {
        return $message;
    } 
     
    // Change the verification error message
    $message = __('You are unable to apply as an individual volunteer because you do not meet the minimum age requirement. Please contact the site admin with other ways you can help support the cause.', 'text-domain');
	
    return $message;
	
}
 
add_filter( 'wpforms_form_locker_age_get_error_message', 'wpf_dev_form_locker_restriction_message', 10, 3 );

This snippet will only run on the form ID 2189, you will need to update this ID to match your own. For assistance in finding your form ID, please review this tutorial.

When a visitor doesn’t meet the age verification check now, they will see your customized message.

using this snippet you can now customize the age verification message

And that’s all you need to customize the message! Would you like to show the number of entries left on a form with the Form Locker addon’s entry limit? Check out our tutorial on How to Display Remaining Entry Limit Number.