How to Display Remaining Entry Limit Number


Would you like to know how to display the remaining entry limit on your form with the Form Locker Addon? This is especially helpful if you’d like to let your visitors know how many entries are left. In this tutorial, we’ll show you how to use PHP to show the remaining entries on the form.

Within the Form Locker qddon, you can choose to limit the number of entries that can be submitted for a form.

After that entry limit is reached, the Form Locker addon will automatically close your form.

For our tutorial, we want our visitors to see how many entries are left before the form will close.

Creating your form

To begin, we’ll create a new form and add our fields. For the purpose of this tutorial we’re only going to collect the Name and Email Address for an entry.

If you need any help in creating your form, please see this documentation.

Enabling the entry limit

Next, we’ll enable the entry limit on the form by clicking the Settings tab and then selecting the Form Locker tab. Under the Entry Limits & Restrictions, we’re going to slide the toggle to Enable total entry limit, set the Limit amount, and the Message that will display when the form is closed.

enable the form locker entry limit

Adding the snippet

Finally, we’ll need to add this snippet to our site.

If you’re not sure how to add snippets to your site, please review this tutorial.

 * Display remaining entry limit.
 * @link

function wpf_dev_remaining_entries( $form_data ) {
    // Optional, you can limit to specific forms. Below, we restrict output to
    // form #1899.
    if ( absint( $form_data[ 'id' ] ) !== 1899 ) {
    if ( empty( $form_data[ 'settings' ][ 'form_locker_entry_limit_enable' ] ) ) {
    $reference = ! empty( $form_data[ 'settings' ][ 'form_locker_entry_limit' ] ) ? (int) $form_data[ 'settings' ][ 'form_locker_entry_limit' ] : 0;
    $entries_count = wpforms()->entry->get_entries( array( 'form_id' => $form_data[ 'id' ] ), true );
    $result = absint( $reference - $entries_count );
    echo '<p>' . esc_html( $result ) . __( ' entries remaining', 'text-domain' ) . '</p>';
add_action( 'wpforms_frontend_output', 'wpf_dev_remaining_entries', 10, 1 );

You’ll need to update the form ID in the above snippet to match your own form ID. If you need assistance in finding your form ID, please check out this tutorial.

Once the code is added, the entry limit will display below the form’s title and above the form fields.

Now you can see we're displaying the remaining entry limit on our form

The number displayed will be determined when the form is loaded. As a result, this number may not be accurate by the time the user submits the form.

And that’s all you need to display the remaining entry number on your Form Locker forms. Would you like to display a count of how many form submissions your form has received? Take a look at our tutorial on How to Display Entry Submissions Count for a Specific Form.


Action Reference: wpforms_frontend_output