How to Add an Incremental ID to Your WPForms Submissions
Content
Many WordPress site owners need to assign a unique, sequential number to each form submission, such as for grant applications, order numbers, or support tickets. A common challenge is finding a way to generate this ID automatically within the free version of WPForms, which doesn't natively store entries.
Why This Happens
The free version of WPForms, WPForms Lite, is designed as a form builder and submission collector. Its core functionality does not include a built-in entry management system or the ability to generate and store unique incremental IDs for each submission. This is a feature typically associated with the paid versions that include entry storage.
Solution: Using a Custom Code Snippet
Fortunately, you can implement this functionality yourself using a custom code snippet. The WPForms team provides official developer documentation for this exact purpose. This method uses a hidden field and a WordPress hook to assign a sequential number to each new form submission.
Step-by-Step Implementation
- Add a Hidden Field to Your Form: In your WPForms form builder, add a 'Hidden' field. This field will store the unique ID.
- Install a Code Snippets Plugin: For beginners, the safest way to add custom code is by using the 'Code Snippets' plugin. Install and activate it from your WordPress admin dashboard under Plugins > Add New.
- Add the New Snippet: In the Snippets menu, create a new snippet and paste the following code. Remember to replace
123with your actual form ID and4with the ID of your hidden field.
/**
* Add an incremental ID to WPForms form submissions.
*/
add_action( 'wpforms_process', function( $fields, $entry, $form_data ) {
// Only run for a specific form ID; replace 123 with your form's ID.
if ( $form_data['id'] != 123 ) {
return;
}
// Get the last used ID number from the WordPress options table.
$last_id = get_option( 'wpforms_entry_id', 0 );
// Increment the ID by 1.
$new_id = $last_id + 1;
// Update the option table with the new last used ID.
update_option( 'wpforms_entry_id', $new_id );
// Update the value of the hidden field; replace 4 with your field ID.
$fields[4]['value'] = $new_id;
// Return the modified fields array.
return $fields;
}, 10, 3 );
- Activate the Snippet: Save and activate the snippet. The code will now run whenever your specified form is submitted.
Important Considerations
- Testing: Always test this functionality on a staging site before implementing it on your live website.
- Backups: The generated ID is stored in your WordPress options table. It is independent of form entry storage, which is why it works in WPForms Lite.
- Custom Development: For more complex requirements, such as needing the ID to be reset annually or to include a prefix (e.g., APP-1001), you may need to hire a developer for further customization. The WPForms team often recommends services like Codeable or Seahawk for such custom work.
This approach provides a reliable method for generating unique application or order numbers directly within your form submissions, extending the functionality of WPForms Lite to meet your specific needs.
Related Support Threads Support
-
How to make search box and get search data from excel file ?https://wordpress.org/support/topic/how-to-make-search-box-and-get-search-data-from-excel-file/
-
Extract Prefix for a single userhttps://wordpress.org/support/topic/extract-prefix-for-a-single-user/
-
Lookup Fieldshttps://wordpress.org/support/topic/lookup-fields-2/
-
Automatic completion of all company data based only on the IČO number?https://wordpress.org/support/topic/automatic-completion-of-all-company-data-based-only-on-the-ico-number/
-
Is there a way to Split Input from a Text Field with a Mask?https://wordpress.org/support/topic/is-there-a-way-to-split-input-from-a-text-field-with-a-mask/
-
How can we Split a Fieldhttps://wordpress.org/support/topic/how-can-we-split-a-field/
-
How do I echo an image only if field contains data?https://wordpress.org/support/topic/how-do-i-echo-an-image-only-if-field-contains-data/
-
Feature Requesthttps://wordpress.org/support/topic/feature-request-968/
-
Validation using databasehttps://wordpress.org/support/topic/validation-using-database/
-
Need Help regarding formulas for the Quiz templatehttps://wordpress.org/support/topic/need-help-regarding-formulas-for-the-quiz-template/
-
Execute php code if required fields are not compiledhttps://wordpress.org/support/topic/execute-php-code-if-required-fields-are-not-compiled/
-
different entry columns created for every logic answerhttps://wordpress.org/support/topic/different-entry-columns-created-for-every-logic-answer/
-
Hide empty fieldshttps://wordpress.org/support/topic/hide-empty-fields-6/
-
Total Fieldhttps://wordpress.org/support/topic/total-field/
-
Feature Request: Calculated Fieldhttps://wordpress.org/support/topic/feature-request-976/
-
Conditional number of fields based on numeric entryhttps://wordpress.org/support/topic/conditional-number-of-fields-based-on-numeric-entry/
-
Add Incremental ID to Individual Forms in the free versionhttps://wordpress.org/support/topic/add-incremental-id-to-individual-forms-in-the-free-version/
-
Input Maskhttps://wordpress.org/support/topic/input-mask-5/
-
Formularfeld mit fixer Vorwahl +43, geht das?https://wordpress.org/support/topic/formularfeld-mit-fixer-vorwahl-43-geht-das/
-
Own ID when submitting a formhttps://wordpress.org/support/topic/own-id-when-submitting-a-form/