To count the number of records for a certain form and insert a record count in a field in a form, the best way is to create a custom submit button which has in an Actionscript an Ajax call to the database to get the count. That way, records will be counted when the submit button is pressed.

To do so, please follow these steps:

1) Go to your form's Properties and set "Include submit button" to "No". That will remove regular submit button.

2) At the end of your form create new element of Submit button type. What you write in the "Value" field for that button element is what will be displayed on that button in your form, so that it the place where you should put, for example, "SUBMIT" since this button will use to submit the form.

3) Go to the "Advanced" properties of that newly created submit button element and in the "Actionscript" section set "Type" to "Custom" and mark "Click" as "Action".
In the code are below put the following code:

 

function ff_submit_action(element, action)
{
jQuery.ajax({
type: 'GET',
url: 'http://localhost/value.php',
data: 'test',
success: function(data){
ff_getElementByName("ELEMENTNAME").value = data;

if(typeof bfUseErrorAlerts != 'undefined'){
JQuery(".bfErrorMessage").html('');
JQuery(".bfErrorMessage").css("display","none");
}
error = ff_validation(0);
if (error != '') {

if(typeof bfUseErrorAlerts == 'undefined'){
swal(error);
} else {
bfShowErrors(error);
}
ff_validationFocus();
} else
ff_submitForm();
}
});
} // ff_submit_action

 

NOTE: In the code above you have to replace "submit" with the name of the submit button that you have created.
Furthermore, replace ELEMENTNAME with the name of the name of element in your form which should be filled with count number.
Finally, make sure to replace 'http://localhost/value.php' with the correct path for your site to the "value.php" file.

4) Go to the Joomla root folder and create there file named value.php with the following content:

<?php
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.

That will fill the form field with the record count.

Solution provided by MihaelaK ( thanks ).

Special Offer

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 sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!