BF : count number of form record (javascipt)

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

Gilles361 created the topic: BF : count number of form record (javascipt)

I've a multi-pages BF. I'd like to have a hidden element column, with number of form records: 1, 2, 3...,600,601,...

So I've created a hidden element with PHP value : <?php $db = JFactory::getDBO(); $db->setQuery('Select Count(*) From #__facileforms_records Where name="MyFormName"'); return $db->loadResult()+1; ?>

Issue : sometime (6% error), it doesn't count correct number when multiple connections in parallel (2 in same minute). So I may have values as following: 1,2,3,3,5,6,7,6,6,7,11,...

A/ How may I fix ths bad counts?
B/ Can I use a javascript to do the job?

C/ I create my hidden element value, before submitting. May I count records after submitting?

D/ May I use an external record value, that I would increment
Record XXX (reference) - Number = 112..., then I would read (112), then increment to 113 (for next read)... this record number...
It would provide me the "number of records"

Any other idea to perform a perfect record count increment?

Thanks, Gil
  • mihaela
  • Away
  • Administrator
  • Administrator
  • Posts: 2571
  • Karma: 87
  • Thank you received: 344

mihaela replied the topic: BF : count number of form record (javascipt)


By putting:
<?php $db = JFactory::getDBO(); $db->setQuery('Select Count(*) From #__facileforms_records Where name="MyFormName"'); return $db->loadResult()+1; ?>
as value of an element, the number of records will be couunted when the form is entered and it may lead to wrong coutning.

I see a way to resolve this. Here is what you could do. You could create a custom submit button which would have in an Actionscript an Ajax call to the database. Therefore, the code will be a combination of JavaScript and PHP.

That way, records will be counted when the submit button is pressed so the number of wrong counts should be really minimized as much as possible.

Here are the instructions on how to make it work that way:

1) The Actionscript for custom submit button should look like this:
function ff_submit_action(element, action)
        type: 'GET',
        url: 'http://localhost/value.php',
        data: 'test',
        success: function(data){
           ff_getElementByName("HIDDENELEMENTNAME").value = data; 

if(typeof bfUseErrorAlerts != 'undefined'){
    error = ff_validation(0);
    if (error != '') {

        if(typeof bfUseErrorAlerts == 'undefined'){
        } else {
    } else
} // ff_submit_action
NOTE: in the code above you have to replace HIDDENELEMENTNAME with the name of the hidden input field which should be filled in with the records count.
Also, make sure to replace 'http://localhost/value.php' with the correct path for your site to the value.php file.

2) Then go to the Joomla root folder and create there file named value.php with the following content:
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/' )); 
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );

$db = JFactory::getDBO(); 
$db->setQuery('Select Count(*) From #__facileforms_records Where name="MyFormName"'); 
$result =  $db->loadResult()+1; 

echo json_encode($result);
NOTE: Make sure to replace MyFormName with the actual name of your form.

As for counting results after submitting. It is possible, but then no count would be submitted along with the record. You could only count after the record is submitted and saved to the database in sence that you would count all records including that one and then you could write code to change number of records in database.

I think this answers more or less all of your questions. If you have more questions, feel free to ask.

Let me know whether this solution works for you.


Moderators: ForumSupporttomeperica
Time to create page: 0.064 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 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