Is there a way to limit the number of forms that can be submitted? This would come in handy if I needed to limit the number of entries for a contest, or registration for an event, etc.
Yes, you can do this by creating a BEFORE FORM PIECE.
To do that, go to your form's properties > Advanced Tab > More Options, then click on the PIECES tab. In the BEFORE FORM section, click on the "Custom" radio button and add the code below.
IMPORTANT: You will need to change the "999" in the code below to the ID of your form. To find the ID number, go to Components > BreezingForms > Manage Forms. You will find the ID number for your form in the Script ID column.
To set a limit on the number of submissions, change the "100" in the load result line to whatever number of submissions you want to allow.
You will also need to replace the URL in the Header Location to the URL for your Limit Exceeded notice page.
$db = JFactory::getDBO(); $db-> setQuery("Select count(id) From #__facileforms_records Where form = 999"); if( $db->loadResult() > 100 ) { // replace index.php with the url to an article explaining that the max. amount has been reached header("Location: index.php"); exit; }
Or you can limit submissions by IP like this:
$ip=$_SERVER['REMOTE_ADDR'];; $db = JFactory::getDBO(); $db->setQuery("Select count(id) From #__facileforms_records Where ip ='".$ip."' and form = 999"); if( $db->loadResult() > 3 ){ // replace index.php with the url to an article explaining that the max. amount has been reached header("Location: index.php"); exit; }
The code above will limit to 3 submissions per IP address.
Or you can limit submissions by user like this:
$user = JFactory::getUser(); $db = JFactory::getDbo(); $db->setQuery('SELECT COUNT(id) FROM #__facileforms_records WHERE user_id ="'.$user->id.'" AND form = 999'); $db->loadResult(); if($db->loadResult() > 0){ // replace index.php with the url to an article explaining that the max. amount has been reached header("Location: https://crosstec.org/en/"); exit; }
This will limit to one single submission per user.