Update field value before submission in WPForms

A laptop displaying a WPForms contact-form confirmation with the generated eight-digit request ID 88045722.

In a WPForms customization project, I needed to generate an eight-digit reference number and insert it into a hidden field before submission, using a PHP filter without JavaScript.

I used the wpforms_process_filter hook to update the hidden field programmatically.

How the filter works

The “wpforms_process_filter” hook in the WPForms plugin allows you to modify the form data before it is submitted. You can use this hook to change the value of a specific field before the form is processed.

This filter includes three parameters:

  • $fields: sanitized entry field values and properties.
  • $entry: the original $_POST data.
  • $form_data: the form settings and data.

Add a request ID to the form

Start with a contact form and add a hidden field named “Request ID”.

WPForms configuration example

Insert Hidden Field on WPForms

WPForms configuration example

Note down the field ID and form ID

Use the form ID and field ID to target the correct form, so the filter only changes the intended field.

Add the following code to your custom site plugin or child theme’s functions.php file. Replace the example form ID and field ID with your own, and test the change in staging first.

/**
 * Update field value before submission in WPForms
 *
 * @link  https://iamavi.com/update-field-value-before-submission-in-wpforms/
 *
 * @param  array  $fields     Sanitized entry field values/properties.
 * @param  array  $entry      Original $_POST global.
 * @param  array  $form_data  Form data and settings.
 *
 * @return array
 */

function av_wpforms_process_filter( $fields, $entry, $form_data ) {
    //  Validate the form ID
	if($form_data['id'] != 5804){
        return $fields;
    }

    // Generate 8 digit random number
    $request_id = rand(10000000,99999999);

    // Update the hidden field value
    $fields[3]['value'] = $request_id;

    return $fields;
}
add_filter( 'wpforms_process_filter', 'av_wpforms_process_filter', 10, 3 );

Update the confirmation message to include the generated Request ID. It will then appear after the form is submitted.

WPForms configuration example

Modify the WPForms confirmation message

Submit a test entry and check the confirmation message.

WPForms configuration example

Check that the generated reference appears in the confirmation message.

The hidden field now receives its value on the server before the form is processed.

Need Help With WPForms Customization?

If you need an experienced WordPress developer to assist you with customizing your forms using the plugin WPForms, you can reach out to me directly.

Contact Me

A note on request IDs

This original example generates a random eight-digit reference. Random values can collide, so this is not a guarantee of uniqueness. If the ID is used for orders or other critical records, enforce uniqueness in your storage layer or use an appropriate unique identifier. Test custom code in staging before deploying it.

Last updated Oct 25, 2026

Keep reading

More from the journal

All articles
A laptop and connected portable backup drive on a naturally lit wooden work desk.

How to update WordPress without breaking your live site

A practical workflow for WordPress updates: prepare a recoverable backup, test a staging copy, check the journeys that matter, and plan a safe release.

Rows of physical servers with metal ventilation grilles, status lights and Ethernet cables in a working server room.

PHP2SHELL: what happened and how to secure your WordPress site

PHP2SHELL exposed a risk below WordPress itself. Understand the October 2026 incident, the PHP patches and follow-up advisory, and the security checks every site owner should make.

A hand holding a smartphone displaying a website, with a laptop softly blurred on the desk behind it.

Why your website feels slow: a guide to Core Web Vitals

Loading, responsiveness and layout stability are different problems. Learn how LCP, INP and CLS help you find the right performance fix.