Display participats limit in form text

Cugar 08 Dec, 2014
I would like to display at top of the form how many participants are still be able to sign up for an event.

So, I thought, I try something like this:

1) 'db read' and count the already signed up participants and subtract from a limit found in a 'mysql config_table'
But how do I do this?
Creating a sql statement to return the number is sort of simple - but where do I insert such a statement??


2) Display the resulting number:
Ideal outcome is a text which says at top of the form: "There are xxx slots left"
Don't want to use a text box for this... Looks a bit odd - even if styled.... a <span> or <div> is probably what I'm looking for..

Any ideas on how to accomplish this?

Thanks a ton for your help.
Cugar 09 Dec, 2014
So, after some digging, I decided to use a Custom Code block and not a Db Read action.
In there, I put the following code:

<?php

$db = JFactory::getDBO();
$query = "
    SELECT config.max_teilnehmer, config.timelimit, COUNT(anmeldung.`id`) as 'counti'
        FROM `#__aa_anmeldung` AS anmeldung JOIN `#__aa_event_config` AS config
";
$db->setQuery($query);
$data = $db->loadObject();

$form->data['teilnehmer'] = $data->max_teilnehmer - $data->counti;

?>


I'm already using this query in an event switcher to determine whether the timelimit and participant limit is reached - to basically display a message about these events - rather than the form.

Now, I'm executing this sql query again... This is somewhat in efficient...

is it possible to save the data from the event switcher call and then 'just' fill my form_id field ??

What is missing on top, is to format the output nicely...

Do I have to move under 'Code' to 'form type' == 'Custom Code' instead of 'Wizard designer'??

Or is there a better trick?

Thanks, Cugar
GreyHead 09 Dec, 2014
Hi Cugar,

I would do it in a Custom Code action in the On Load event of your form.
<?php
$db = JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `#__some_table`
        WHERE `xxx` = 'yyy' ;
";
$db->setQuery($query);
$count = $db->loadResult();
$form->data['count'] = 99 - $count;
?>
Then you can show the count in a Custom element in the Designer tab:
<p>There are <?php echo $form->data['count']; ?> places left.</p>

Bob

Later: updated to correct the display code. Bob
Cugar 09 Dec, 2014
HI Bob,

cool - pretty much what I'm looking for - just that {count} is not replaced 😟 .

I used Pure code: No and Yes
The Custom element is outside a container.
The php works - a text box is filled with the correct number...

What am I doing wrong here?

Thanks Cugar
Cugar 10 Dec, 2014
OK, pulled out all my remaining hair on this and I don't get it to work....
I tried everything, rearranging, etc, etc,...
A text field is filled, but the {} variable is just not touched.

Bob, can you pls do me a favor and confirm, that his functionality is working and that there is no bug?

Thanks, Cugar
GreyHead 10 Dec, 2014
Answer
Hi Cugar,

Please try this instead
<p>There are <?php echo $form->data['count']; ?> places left.</p>

Bob
Cugar 10 Dec, 2014
Hi Bob, this works like a charm! 😀

Thanks!

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