-
- How to Increment a Count on Each Form Submission
- Adding an “Other” Option
- Adding a Unique ID to Each Form Submission
- Show or Hide Form Fields Based on User Joomla User Group
- Disabling Browser Autocomplete for Form Fields
- Scroll the Page to the Top When a Long Form is Submitted
- Display Submissions Count for a Specific Form
- Populate Drop Down, Radio Buttons or Checkboxes with a CSV File
- Automatically Delete Submissions Older Than X Days
- Silently POST Submitted Data to Any API or URL
- Automatically Save Each Submission to a JSON file
- Authenticate and Login a User with a Custom Joomla Form
- Auto-Populate a Form Field with an Article Data
- Add a placeholder text to a Dropdown field
- Create Multilingual Forms in Joomla
- Redirect User to a URL After Form Submission
- Importing and Exporting Forms
- Exporting Form Submissions
- Display Convert Forms in a popup
-
- How to Create a Quiz Form
- Displaying a Popup After Form Submission Using EngageBox
- Using the Conditional Content Shortcode in Convert Forms
- Copy Value From One Field to Another
- Submission Tasks
- Exporting Form Submissions with a Webhook URL
- Conditional Fields
- PDF Form Submissions
- Working with Input Masks
- Field Calculations
- Auto-Populate Form Fields Using Query String
- Smart Tags
-
- Enable Minimum Time to Submit
- Restrict Form Submissions Based on IP
- Enforcing a Custom Password Policy in Convert Forms
- Add Cloudflare Turnstile to your Joomla Form
- Implement the Iubenda Consent Database in Joomla with Convert Forms
- Add Custom Validations to Fields and Forms
- Add Math Captcha to your Form
- Prevent a Field From Saving in the Database
- Add hCaptcha to your Form
- Enable Double Opt-in
- Allow Form Submissions in Specific Date Range
- Ensure a Unique Value is Entered Into a Field
- Block Form Submissions Containing Profanity (Bad Words)
- Block Email Addresses or Email Domains
- Honeypot
- Setting Up Google reCAPTCHA
- Create GDPR Compliant Forms
How to Increment a Count on Each Form Submission
Every submission in Convert Forms receives a unique, sequential ID that identifies it across all forms. However, sometimes you may want a counter starting from 1 for each form—useful for things like per-form reference numbers, ticket IDs, or order numbers.
This guide shows you how to add an auto-incrementing counter to your form using a simple PHP snippet. The counter is stored in a Hidden field and increases with every new submission for that specific form. You can also format the counter with leading zeros (e.g., 00001, 00002) for a consistent, professional appearance.
Setting Up the Form
- Open the form builder by creating or editing your existing form.
- Add a Hidden field (found under the Add Fields tab). Users won’t see this field, but it will store the counter value behind the scenes.
- After adding the field, set its name to
total
.
Adding the Code Snippet
Place the following PHP script into the PHP Scripts → Form Process option:
// Name of the Hidden field that will store the counter
$myFormField = 'total';
// Minimum number of digits for the counter (e.g., 5 will produce 00001, 00002, ...)
$minDigitLength = 5;
// Get all submissions for this form (with any state)
$formSubmissions = ConvertForms\Api::getFormSubmissions($form['id'], ['state' => [0,1,2]]);
// Calculate the new counter value by adding 1 to the current number of submissions
$newTotalSubmissions = count($formSubmissions) + 1;
// Pad the counter with leading zeros if needed
if ($minDigitLength > 0)
{
$newTotalSubmissions = str_pad($newTotalSubmissions, $minDigitLength, '0', STR_PAD_LEFT);
}
// Store the counter value in the Hidden field
$post[$myFormField] = $newTotalSubmissions;
How It Works
- Field Configuration: The variable
$myFormField
specifies which form field will store the counter value (in this case,total
). - Setting Minimum Digits: The
$minDigitLength
variable defines how many total digits the number should have (default is 5). For example, with five digits, the first submission would be00001
. - Getting Submissions: The script retrieves all existing submissions for your form, including those with any state (published, unpublished, or archived).
- Calculating the New Count: It counts the existing submissions and adds 1 to create the new incremental number.
- Adding Leading Zeros: If
$minDigitLength
is set greater than 0, the script will pad the number with leading zeros to match that length. - Assigning the Value: Finally, the counter value is stored in your hidden field named
total
.
Testing Your Counter
- Submit a test submission through your form.
- Check the submission in Convert Forms » Submissions. You should see your incremental number stored in the Hidden field.
- Submit another test entry to confirm the number increases as expected.
Note: If you want to display this number in your email notifications or confirmation messages, simply add the shortcode {field.total} to any message in your form’s Notifications or Confirmations settings.