BF : count form records, Element value (based on Value)

  • Gilles361
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
  • Posts: 203
  • Thank you received: 5

Gilles361 created the topic: BF : count form records, Element value (based on Value)

Hi,
I've a form (FORMNAME), Element > radio button CHOICE (value = X, Y or Z) (value = text or number)

Once I'm starting my form, I would like to count the number of time I've CHOICE with value X, value Y and value Z. Then I will perform action based on these values...

This could be done using different Hidden elements:
Element ChoiceX could count CHOICE value X, ...

What method would you recommend to do so?
PHP command line or Javascript init action or ...

Thanks, Gil
#238256
  • Posts: 265
  • Karma: 1
  • Thank you received: 31

Eddy.vh replied the topic: BF : count form records, Element value (based on Value)

Bonjour Gilles.

La méthode pour compter le nombre d'enregistrements d'une valeur à déjà été donnée de nombreuses fois sur ce forum.
Une petite recherche avec le mot "count" devrait te donner des résultats.
Il reste à adapter à ta situation.

Cordialement.

Hello Gilles.

The method for counting the number of records of a value has already been given many times on this forum.
A little search with the word "count" should give you results.
It remains to adapt to your situation.

Best regards.
#238270
  • Posts: 2726
  • Karma: 93
  • Thank you received: 369

mihaela replied the topic: BF : count form records, Element value (based on Value)

Hello,

If I've understood correctly, your form has multiple radio buttons with possible choices X,Y or Z and you wish to count the number for example how many times the X was selected as the answer.

You can do that using JavaScript. You can put the code in Actionscript of each radio group that is included in counting or you can write Initialization script like follows.

Go to form's Advanced properties > More options > Scripts and in Initialization script set Type to Custom and put there the following code:
function ff_FORMNAME_init()
{
setInterval('calc()', 500);
} // ff_FORMNAME_init

function calc() {

var sumX = 0;
var sumY = 0;
var sumZ = 0;

if(jQuery('[name="ff_nm_radiogroup1name[]"]:checked').val() == "X") {
	sumX = Number(sumX) + 1;
} 
else if(jQuery('[name="ff_nm_radiogroup1name[]"]:checked').val() == "Y") {
	sumX = Number(sumY) + 1;
} 
else if(jQuery('[name="ff_nm_radiogroup1name[]"]:checked').val() == "Z") {
	sumX = Number(sumZ) + 1;
} 


if(jQuery('[name="ff_nm_radiogroup2name[]"]:checked').val() == "X") {
	sumX = Number(sumX) + 1;
} 
else if(jQuery('[name="ff_nm_radiogroup2name[]"]:checked').val() == "Y") {
	sumX = Number(sumY) + 1;
} 
else if(jQuery('[name="ff_nm_radiogroup2name[]"]:checked').val() == "Z") {
	sumX = Number(sumZ) + 1;
} 

ff_getElementByName('ChoiceX').value = sumX;
ff_getElementByName('ChoiceY').value = sumY;
ff_getElementByName('ChoiceZ').value = sumZ;

}
NOTE: In the code above replace FORMNAME with the actual name of your form.
Also, replace radiogroup1name and radiogroup2name with the actual names of elemetns in your form.

Let me know whether you have managed to set this for your form and whether it is working as you wanted.

Regards,

Mihaela
#238271
  • Posts: 265
  • Karma: 1
  • Thank you received: 31

Eddy.vh replied the topic: BF : count form records, Element value (based on Value)

Peut-être ai-je mal compris la question mais je pense que tu cherches à charger le nombre d'enregistrements de ces valeurs déjà stockées depuis la base de données.

Est-ce bien ça ?


Maybe I misunderstood the question but I think you're trying to load the number of records of these values ​​already stored from the database.

Is that it?
#238272
  • Gilles361
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
  • Posts: 203
  • Thank you received: 5

Gilles361 replied the topic: BF : count form records, Element value (based on Value)

Hi Eddy,
yes, that is correct. Only number of Element records is enough.
If count is over a "Limit" value, I will go to Form closed page.

Solution 1 : In my BF form, I've two Elements : "element-1" and "Element-2"
Both have different count limits, so I need to count each number of "element-1" and "Element-2" record values and not only Form

Solution 2 : In my BF form, I've an "Element-1" with two values "value-1" or "value-2". Both VALUES have different count limits, so I need to count each number of records with "value-1" and "value-2".
If Value-1 = Limit-1 go to For closed Page
If Value-2 = Limit-2 go to For closed Page

Thanks, Gil
#238284
  • Posts: 2726
  • Karma: 93
  • Thank you received: 369

mihaela replied the topic: BF : count form records, Element value (based on Value)

Hello,

Ok, I see I have misunderstood your request before.

You can do this using PHP.
Go to your form's Advanced properties > More options > Form pieces and in Before Form pieces you can write a query to count the wanted value.

You can write code similar to this:
$db = JFactory::getDBO();
$db-> setQuery("Select count(id) From #__facileforms_subrecords Where value= WANTEDVALUE and name=ELEMENTNAME");
if( $db->loadResult() > 100 )
{
     // replace index.php with the url that you wish to recirect to
     header("Location: index.php");
     exit;
}

What this will do is it will redirect or stay at the form based on the query result.

Let me know whetehr this is working as you wanted.

Regards,

Mihaela
#238292
Moderators: ForumSupporttomeperica
Time to create page: 0.057 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here