Forums

Set limit to a field

ucwd 15 Oct, 2009
I have a group that wants a field to be automatically removed from the form once a certain number of people have signed up for that particular time/activities slot. I have been searching everywhere for how to do this in a form and in chronoforms. Can anyone help me in how to set a limit to a particular field (ie 5 people can chose and then it is no long a choice)?

THanks.
GreyHead 16 Oct, 2009
Hi terrihallwd,

You can do this in the Form HTML - add a MySQL query to count the number of sign-ups and don't show the field if the number is five or more.

Bob
ucwd 17 Oct, 2009
Thank you. I don't know how to do that...so guess I'm going to have to go do some research. Thanks for giving me a place to start looking.
GreyHead 17 Oct, 2009
Hi terrihallwd,

How are you setting up the 'record keeping' part of this application? Presumably you have a database table? What are the relevant column names?

Bob
ucwd 18 Oct, 2009
I have the data being collected in a database.

A few of the column names are:

welcometable1
welcometable2
welcometable3
welcometable4
welcometable5

shepherds1
shepherds2
shepherds3
shepherds4
shepherds5

These correspond with the Job and the time slots given. Welcome table - each time slot needs 3. Shepherds - each time slot needs 20.
GreyHead 19 Oct, 2009
Hi terrihallwd,

At the beginning of the Form HTML you'll need something like
<?php
$db =& JFactory::getDBO();
$query = "
  SELECT COUNT(*)
    FROM `#__some_table_name`
    WHERE `some_column_name` = 'some value' ;
";

$db->setQuery($query);
$result = $db->loadResult();

if ( $result >= 5 ) {
?>
// show form html
<?php
} else {
?>
<p>Sorry no places left</p>
<?php
}
?>{/code]
Bob
Mugen 26 Mar, 2010
Hi

can i use cf_id into this code??

<?php
$db =& JFactory::getDBO();
$query = "
  SELECT COUNT(*)
    FROM `#__some_table_name`
    WHERE `cf_id` = 'some value???' ;
";

Iam looking fore a solution to close a course registration form after 20 submissions
(not registrated users)
GreyHead 27 Mar, 2010
Hi mugen,

Yes, but I'm not sure that it will help you. Check the MySQL docs to build the WHERE clause that you need (you may not need one at all).

Bob
Mugen 27 Mar, 2010
Hi Bob
Thanks for your help
here is my code, it´s not changing if cf_id is higher than 10

If i change to,
if ( $result>= 0 ) {

it change the result to "// show form html " as i want

if i look in the database "0" come from field "cf_user_id"
it should lock in field cf_id instead

can you give me some advice

<?php
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM ".$db->nameQuote('#__XXXXXXX')."
WHERE ".$db->nameQuote('cf_id')." = ".$db->quote($value).";
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $result>= 10 ) {
?>
// show form html
<?php
} else {
?>
<p>Sorry no places left</p>
<?php
}
?>
GreyHead 27 Mar, 2010
Hi mugen,

Looks like a problem of comparing apples and pears. I think these two lines should use the same variable:
$count = $db->loadResult();
if ( $result>= 10 ) {

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