BF : count number of form record (javascipt) 1 year 1 day ago #236897

  • Topic Author
  • Gilles361
  • Offline
  • Expert Breezer
  • Expert Breezer
  • Posts: 215
  • Thanks: 5
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

Please Log in or Create an account to join the conversation.

BF : count number of form record (javascipt) 1 year 10 hours ago #236904

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413

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.



Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Moderators: ForumSupport
Time to create page: 0.044 seconds

July Sale!

Discounts for all of our extensions + support. Ending July 31st!

Get Your Subscription Here

Quick Links










Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

Questions et réponses sur les forums de l'AFUJ


Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

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!