I made a form for a kids-recreation week..
Kids can apply by filling in the form. Form works like a charm, data is saved in the database.
Now there is the need to have a limit on the number of applicants. There is only 750 places available.
Is tere a way to count the number of records in the database ? And when it hits 750 a message should be displayed that the max number of applications is reached. So no form displayed...
Any thoughts on this?
Kids can apply by filling in the form. Form works like a charm, data is saved in the database.
Now there is the need to have a limit on the number of applicants. There is only 750 places available.
Is tere a way to count the number of records in the database ? And when it hits 750 a message should be displayed that the max number of applications is reached. So no form displayed...
Any thoughts on this?
Hi wwgg,
You can use an Event Switcher in the form On Load event. Include PHP there to query the database and get the count of applications. If the count is more than 750 then show an 'full' message; if not, show the form using an HTML (Render form action).
So the event switcher would have one event called full with a Display Message action and a Show Stopper action in it.
The PHP would be something like this (this is Joomla! code, needs fixing to work in WordPress):
Bob
You can use an Event Switcher in the form On Load event. Include PHP there to query the database and get the count of applications. If the count is more than 750 then show an 'full' message; if not, show the form using an HTML (Render form action).
So the event switcher would have one event called full with a Display Message action and a Show Stopper action in it.
The PHP would be something like this (this is Joomla! code, needs fixing to work in WordPress):
<?php
$db = \JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `#__some_table' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count >= 750 ) {
return 'full';
}
?>
Bob
I have been struggling for over 4 hours now..
Created the Event Switcher. Have an On Fail and On Success. Works like a charm when I return Fail and Success by hand.
But the record count doesn't seem to wok for me. I've tried to echo the value, but no results :-(
Please help
Created the Event Switcher. Have an On Fail and On Success. Works like a charm when I return Fail and Success by hand.
But the record count doesn't seem to wok for me. I've tried to echo the value, but no results :-(
Please help
<?php
global $wpdb, $aantalrecords ;
echo "Inschrijvingen tellen <BR>";
$aantalrecords = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->wp_chronoengine_chronoforms_datatable_Inschrijven-kinderen ");
echo "aantal inschrijvingen:" .$aantalrecords;
if ( $count >= 750 ) {
return 'full';
}
else {
return 'success';
}
?>
the test form on : http://www.kaartjesvansas.nl/?page=Chronoforms5&chronoform=Inschrijven-kinderen
Hi wwgg,
The default event names are 'success' and 'fail' - to use my code example (and yours) you need to replace those with a single 'full' event.
Bob
The default event names are 'success' and 'fail' - to use my code example (and yours) you need to replace those with a single 'full' event.
Bob
bob,
the problem is the PHP code doesn't echo the number.. so the $count doesn't return any value... So the event is never full....
the problem is the PHP code doesn't echo the number.. so the $count doesn't return any value... So the event is never full....
This topic is locked and no more replies can be posted.