Count Number of Records

Crosstec Blog


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 ).

Add a comment

SAVE INFORMATION IN DB ON EACH MULTIPAGE STEP

SAVE INFORMATION IN DB ON EACH MULTIPAGE STEP

Sometimes when filling out a large form it would come in handy if you can come back at a later point and continue where you last stopped. Unfortunately this is not a built in feature but it can be done with some custom coding and proper setup.


For this to work you will need to have a multipage form.

  1. Disable “Email notification” inside Form Properties as we will use Custom PHP email for this. You can read more on custom PHP emails here : https://crosstec.org/en/support/online-documentation/breezingforms/12-examples-scripts/746-new-custom-php-email-that-includes-attachment.html

  2. On your last form page create a hidden element, and give it name “finished”.

  3. In advance options from this element go to :
    Initscript > Custom > check "Form Entry" > Press "Create Code framework and add this within the code framework. This will populate the hidden field with value of 1.

    ff_getElementByName('finished').value=1;
  4. On each form page you will need to create a CUSTOM BUTTON.
    This button will SAVE all the info to the DB, but WILL NOT trigger an email notification at least not until you come to the last page form where we will make a condition :
if($finished==1){
$this->sendMail();
}

       Go to this buttons Advanced Options > Actionscript > Custom > Actions “Click” > Create code framework and add this code in between {}

switch (action) {
        case 'click':
JQuery.ajax({
          type: "POST",
          url: JQuery(element).closest("form").attr("action"),
          data: JQuery(element).closest("form").serialize(),
          success: function(data) {
            ff_validate_nextpage();
            ff_getElementByName('finished').value=0;
        });
           break;
        default:;
    } // switch

     This will need to be done FOR ALL pages EXCEPT the LAST Page ( NOT THANK YOU PAGE ) where you need to add the following code :

        switch (action) {
        case 'click':
JQuery.ajax({
          type: "POST",
          url: JQuery(element).closest("form").attr("action"),
          data: JQuery(element).closest("form").serialize(),
          success: function(data) {
             ff_validate_nextpage();
            ff_getElementByName('finished').value=1;
        });
           break;
        default:;
    } // switch

 
Now on final page right before the submit following code will set value to “1” which will make to form able to submit the info.

5) Finally you need to create a custom PHP email. Go to  Form properties->advanced->more options->submit pieces->custom and put the following code into the box:

$this->execPieceByName('ff_InitLib');
$finished = ff_getSubmit('finished');
$fromname = 'Your from Name'; //  /* Change to desired from name */
$recipient = 'your@email.com'; /* Change to Your Admin Email Address */

// Create the Body format for use in e-mail

foreach ($this->maildata as $data)
{
     if ($data[_FF_DATA_TYPE] != 'Hidden Input')
          $body .= $data[_FF_DATA_TITLE].":
          ".$data[_FF_DATA_VALUE].nl();
}

if($finished==1){ 
$this->sendMail($from, $fromname, $recipient, $body); // This line actually emails the form.
}

Note that in the code above we are transferring the variable 'finished' so we can test to see if it’s value iz 0 or 1. Based on that we do the following : 

if($finished==1){ 
$this->sendMail($from, $fromname, $recipient, $body); // This line actually emails the form.

 This will send the info saved previously as one email notification.

If you have additional questions about this please visit our Forums.



Add a comment

HOW-TO #2: Problems with caching? - CacheControl

 

A lot of websites are using caching. What exactly is caching? One definition says that caching (pronounced “cashing”) is the process of storing data in a cache. A cache is a temporary storage area. For example, the files you automatically request by looking at a Web page are stored on your hard disk in a cache subdirectory under the directory for your browser.

It's an excellent way to speed up your website, but it has some drawbacks. The way caching works is that it creates a sort of a screenshot of your webpage and serves that to the user. That means that once your caching plugin caches your webpage containing a Breezing Form, it won't have any functionality. It will only have the appearance of a normally functioning form, but it won't actually be functional.

So, besides the usual disable the caching solution, there is an alternative. CacheControl is a powerful plugin that disables caching for specific parameters. Let's get started.

Add a comment

Read more: HOW-TO #2: Problems with caching? - CacheControl

Joomla 4 - What to expect ?

Joomla 4 - What to expect ?

Joomla! 4.x is the next major version of the Joomla! CMS.
This release will introduce new features, raise the minimum supported PHP version to PHP 7, as well as remove previously deprecated functionality.
Joomla 4 will provide simplicity and a better user experience while also being a more powerful system for developers.

Main Features

  • New core UI based on Bootstrap 4
  • Use of more Joomla! Framework packages
  • Refactored event management system
  • Introduction of a service container for global dependency management/injection
  • Removal of jQuery from core
  • Introduction of Framework agnostic Web Components
  • Faster page loading times

 

Features under development in Joomla 4.0

  • MVC layer improvements
  • Full code namespacing
  • User Interface Backend template, Frontend template
  • New Media Manager
  • Framework and General Improvements

Joomla 4 Tutorials and resources




Add a comment

HOW-TO #1: Debugging your forms - E-MAIL

 

 HOW TO DEBUG YOUR FORMS

You created a new form, added all the elements, set all the validations, added some scripts and published the form to a menu item. With pride, you open the newly created page, fill out the fields to test it, press that Submit button and suddenly, nothing happens. What's wrong, you might ask yourself. Well, to be honest, there can be a number of things that went wrong. A lot of times, the problem is a simple typo or an opened tag without its closing tag or the wrong name of a field. All those issues are easily detectable and fixable if you know where and how to look. In this series, we'll try to teach you how to do exactly that and you'll get some insight in how we try to debug your forms when you report an issue.

Add a comment

Read more: HOW-TO #1: Debugging your forms - E-MAIL

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!