Scenario
You want to prevent users from submitting a form if certain criteria is reached.
For example, you’re hosting events with limited seating. Once the seating limit for the event is reached, you want to make sure no more users can register and alert them that the event is full.
In Knack, this kind of scenario can be accomplished using page rules.
See it in action
At the end of this tutorial you will have a working page for users to register to limited-availability events. If the event has no more availability, the user will see an alert message and the registration form will be hidden:
Requirements
This how-to assumes you already have the following requirements fulfilled:
-
A parent object (Events) that needs a limited amount of connected records
-
A child object (Registrations) with a one-to-many connection to the parent (Events)
-
A start page displaying records from the parent object (Events)
Steps
Add a field to track the limit
You’ll need to store the number of children (registrations) that each parent record (event) is limited to.
In the Events object, add a new number field called "Registration limit":
Add a field to count registrations
Before you can prevent the user from doing anything, you need to know how many registrations have already been submitted for a specific event.
In the Events object, add a count field called "Registration count" that counts the number of Registration records:
Knack Tip: Don’t see a "Count" field as an option? Make sure that your Registrations object has a connection pointing to the Events object.
Add a field to calculate remaining registrations
Now you can calculate the remaining registrations by subtracting the count field in step 2 from the limit field in step 1.
In the Events object, add a new equation field called "Registrations remaining" with the following formula:
{Registration limit} - {Registration count}
Your Events object should now look like this:
Add a child page
Find the start page that users will access to view the events. If you don’t have one yet, you can follow the steps here to create a new one. If you already have an existing start page with views, you can click on the "Links" tab in your view to add a new link to view more details as seen here.
Regardless of which step you take here, when creating your new child page be sure to add a new registration form view along with the details view:
Knack Tip: Not seeing the form option for "Registrations"? Make sure you have a connection between the the Event and the Registration.
Add the page rules
The final step is to add page rules that will trigger when the number of registrations reaches the limit.
From the child page, click on the "Rules" tab in the top menu and click on the “Add rule” button to add your first rule:
Set your rule criteria so that it triggers when "Remaining registrations" is lower than 1.
The first rule will hide the registration view, so the action should remain as "Hide views". Click the box for the “Add Registration form”:
Add a second rule with the same criteria as the first rule and set the "action" to “Show a message.” Finally, configure your message by choosing between four different backgrounds, writing your own message, and choosing whether the user can or can not dismiss the message.
Save the rules by pressing the Save rules button:
You’re now successfully hiding the registration view as soon as the registration limit reaches 0!
Notes
-
This will not prevent a single user from submitting multiple registrations, the count is based on all connected children records.
-
You can add filters to your count and only track ‘paid’ registrations, exclude ‘cancelled’ registrations, etc.