Forums

Count registration members

akifoki 03 Nov, 2014
Hi Everybody! I created a registration form for an event, connected to a database. There is a field, where you can give the number of registrated persons. There is a dropdown, where you can select which event (A, B, C, D) would you visit.

Is it possible, to restrict registration on those event, where the number of registrated persons reached the limit? (for example A event 20 person, B event 32 person).

Thanks!
GreyHead 03 Nov, 2014
Hi akifoki,

Yes. You'll need to use PHP in a Custom Code action to query the database, check the number of remaining places and show or hide the options in the drop-down.

Bob
akifoki 03 Nov, 2014
Thanks GreyHead,

Could you please add some instructions how to hide an option in the drop-down? For the custom code and querying the db I found some solutions in the forum, but not for hiding one of a drop down element...
GreyHead 03 Nov, 2014
Hi Akifoki,

I would probably do it all with Custom Code. How exactly are you recording the events and registrations in the database tables?

Bob
akifoki 03 Nov, 2014
In a dropdown you can add a nubmer of persons, this goes to a field in the db. Than you can select the event (Event A, Event B, etc) from a dropdown, this goes to another field in the db. I think i should run a SELECT SUM() to get the number of persons on every events. The event that reached the limit sholud not be displayed in a dropdown. If there is an easier way, I accept it...
GreyHead 08 Nov, 2014
Hi akifoki,

I think that SELECT SUM() is the right way to go. I'd combine that with some custom PHP to create an array of results to be used in the drop-down options. Something like this
<?php
$db = JFactory::getDBO();
$query = "
    SELECT `event`,SUM(`guests`) as 'count'
        FROM `#__some_table`
        GROUP BY `event` ;
";
$db->setQuery($query);
$data = $db->loadObjectList();
$options = array();
$event_max = array(
  'event_a' => 99,
  'event_b' => 10,
  . . . 
}
foreach ( $data as $d ) {
  if ( $event_max[$d->event] > $d->count ) {
    $options[] = array('val' => $d->event, 'text' => $d->event);
  }
}
$form->data['options'] = $options
?>
!!! Not tested and may need debugging !!!

This should add info into the $form->data[''] array that you can then use in the dynamic data setting of a drop-down element.

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