Forums

set limit for registration

thyl123 19 Jan, 2013
Hi,

i use chronoforms as a registration event system.

Is it possible to set a limit? (no more entries in the database, e.g. limit of 200 people)

After 200 people it should not be possible to register.
GreyHead 19 Jan, 2013
Hi thyl123,

In the On Load event add a Custom Code action with a MySQL query that checks the number of registrations. If its less than 200 show the form, if it's 200 or more then redirect them to a 'We're Full' message.

Bob
thyl123 19 Jan, 2013
Ok, i have no experience with mysql,

Can you please post me the query? :-)

Many thanks!
GreyHead 19 Jan, 2013
Hi thyl123,

<?php
$db =& JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `#__some_table_name`
        WHERE `some_column` = 'some_value' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 200 ) {
  // redirect the user
}
?>


Bob
thyl123 19 Jan, 2013
Hi Bob,

many thanks for your post!!

Which positions do i have to overwrite now?
FROM `#tt7xy_chronoforms_data_Spargelturnier_Test`
        WHERE `Selector` = '1' ;  // I set a new field in the database which have the default value 1 to count it
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 200 ) {
  // redirect the user     //how can i redirect the user? i want a message which says: Registration full like a popup (with OK button) and then a redirection to Home
}
?>
thyl123 20 Jan, 2013
I got it:

Redirection:
header( 'Location: http://www.your-side.com' ) ;
GreyHead 21 Jan, 2013
Hi thyl123,

You could also use the Joomla! Redirection code:
. . .
if ( $count > 200 ) {
  $mainframe =& JFactory::getApplication();
  $mainframe->redirect('index.php', 'Sorry, registration is full');
}
?>

Bob
thyl123 29 May, 2013
Sorry to open this thread again.

Does this code also works on a xampp server?

I cloned my homepage and tried to use this limitation, but it doesen't work.

I tried it on my real homepage. It also doesn't work. I have installed the new version of chronoforms V4.

<?php
$db =& JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `tt7vy_chronoforms_data_Spargelturnier_2014`
        WHERE `Selector` = '1' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 4 ) {
  // redirect the user
   header( 'Location: http://www.bsvslr.de/index.php/wir-sind-voll.html' ) ;
}
?>


I do not find the mistake. DB table is correct, Selector is set.

Can someone help me?
GreyHead 29 May, 2013
Hi thyl123,

It looks OK to me; I use XAMPP and would expect that to work, though I wouldn't use location() for the redirection but the Joomla! $mainframe->redirect();

Where exactly do you have this code? Have you checked the query in PHPMyAdmin?

Bob
thyl123 29 May, 2013
I think i got the error: I have JOTCache installed

--> The message couldn't appear, because the side was cached.

That was the problem. I excluded Chronoforms from caching, now it works.

Only question: How do I use this code?
$mainframe->redirect(http://www.bsvslr.de/index.php/wir-sind-voll.html); 
That doesn't work.
GreyHead 29 May, 2013
Hi thyl123,

Yes but with quotes round the URL
<?php
$mainframe->redirect('http://www.bsvslr.de/index.php/wir-sind-voll.html'); 
?>

or, a little better because it's not domain dependent:
<?php
$mainframe->redirect(JURI::root().'index.php/wir-sind-voll.html'); 
?>

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