Forums

How can i disable a form after a certain amount of people have completed it?

t.hanson 25 Mar, 2015
Hello,

I need my form to disable or be inaccessible to people after a certain amount of people have submitted it.

I am using the form to collect booking information for courses which is emailed to the business manager who then manually creates invoices to send out.

The amount of people will change form to form but will generally be between 6 - 100 people.

Is this possible?
GreyHead 25 Mar, 2015
1 Likes
Hi t.hanson,

Save the data to a database table so that you have a record of the number of subscriptions. Check this with a Custom Code action in the Form On Load event
<?php
$db =& JFactory::getDBO();
$query = "
    SELECT COUNT
        FROM `#__some_table`
        WHERE `course_id` = 'xxx' ;
";
$db->setQuery($query);
$count = $db->loadResult();
$form->data['open'] = false;
If ( $count < 999 ) {
  $form->data['open'] = true;
}
?>
Then you can use $form->data['open'] to manage the form display. There are various ways that you can do this:

+ Hide/Show containers i.e. Show a 'we're full' message in place of the form.
+ Redirect to another page - a list of similar courses
+ Show a Waiting List form . . .

Bob
t.hanson 25 Mar, 2015
Wonderful, thank you bob.

I'm being preemptive here so it may be a while till a give this a go, but i will report back with my inevitable blunders.
This topic is locked and no more replies can be posted.