Close subscriptions if amount is higher then...

How to close form submissions when a registration limit is reached.

Overview

The issue occurs when a form needs to stop accepting submissions after a set number of entries, such as for event registration with limited spots.
Use an Event Switcher action in the form's On Load event to check the current count from your database. If the count exceeds the limit, trigger a 'failed' event with a Display Message and Show Stopper action to prevent further submissions.

Answered
br brononius 06 Jan, 2017
Hey,

I would like to make a small registration form, that's limited in places.
For this, I want to use a small db table to keep track of it. I was able to count the open positions (see below), but I would like to lock the subscriptions once the number is reached. What the best way to this?

Custom php code to count down free places from 10 for eventA:
$sql = "SELECT * FROM DB_DATA WHERE EVENT = EVENTA";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
$free = 10 - $num_rows;
echo "For the moment, " . "$free" . "places free.";
Gr GreyHead 06 Jan, 2017
Answer
Hi brononius,

To do this, use an Event Switcher action in the form On Load event with one event 'closed'.

Add code like this
<?php
$db = \JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `#__DB_DATA`
        WHERE `EVENT` = 'EVENTA' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 10 ) {
  return 'closed';
}
?>

In the closed event add a Display Message and a Show Stopper action.

Bob
br brononius 07 Jan, 2017
1 Likes
NIce, is working perfectly !
(I just need to replace the 'closed' event with failed).


Thanks!!!
This topic is locked and no more replies can be posted.