Forums

How do I limit the number of submissions for a form?

agondontor 18 Aug, 2011
Hi,

How can I limit the number of submissions for a form. I am creating a form to RSVP for movie passes. I only get a certain number of passes to give out. I need to set a limit on the number of submissions so I don't give out more passes than I am allotted. I also need to limit one submission per registered user.

Thanks for any help you can give.

Agondontor
GreyHead 18 Aug, 2011
Hi Agondontor,

Basically you have to keep a count of the number of passes left. There are various ways to so this but the simplest is to save the requests in the database and check the number that have been issued before you show the form. If the site is likely to be busy then you also need to check on submission as someone else may have taken the last pass while the form was being completed.

The code for the Form HTML would be something like
<?php
$db =& JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `#__some_table`;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 99 ) {
  echo 'Sorry, all the passes have gone.';
  return;
}
?>
. . . // rest of the Form HTML


In CFv3 you can put this in the Form HTML in CFv4 I think I'd use a Custom Code element.

Bob
agondontor 18 Aug, 2011
Thank you GreyHead,

I can't tell you how happy I am to learn that this can be done! In the past we had been using a form generator that had that function but it would not work for us for some unknown reason. We have to babysit every submission list until the desired number was reached. Then we would have to shut it down manually. This was no fun on our busy schedules.

I do have a couple of questions though. I am new at this.

How do I determine the table identification for the code in the form?

And how do I limit one submission per registered user?

Thanks so much for your help.

Agondontor
GreyHead 19 Aug, 2011
Hi Agondontor,

How do I determine the table identification for the code in the form?

Sorry, I don't understand the question?

And how do I limit one submission per registered user?

You add code to the Form HTML to check if this user has already submitted; if they have then show them a message instead of the form.

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