LIMIT THE NUMBER OF SUBMISSIONS

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.

 

1
2
3
4
5
6
7
8
$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:

 

1
2
3
4
5
6
7
8
$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:

1
2
3
4
5
6
7
8
$user=JFactory->getUser();
$db = JFactory::getDBO();
$db->setQuery("Select count(id) From #__facileforms_records Where user_id =".$user->id." and form = 999");
if( $db->loadResult() > 1 ){
  // replace index.php with the url to an article explaining that the max. amount has been reached
  header("Location: index.php");
  exit;
}

 

This will limit to one single submission per user.

WE LOVE JOOMLA

Joomwalker is not affiliated with or endorsed by the Joomla Project or Open Source Matters.
The Joomla name and logo are used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.