list of countries, states and cities used

  • Posts: 50
  • Thank you received: 2

Akbartus replied the topic: list of countries, states and cities used

Dear Mario,

"Country" select list is working. However, it does not save the selected value from "Country list". It only saves "Region" values.

In the image attached by you: Region is Africa, Country is Somalia. When you submit it in CB list view, when you edit the record, it only shows Region Africa
#219404
  • MarioPuco
  • MarioPuco's Avatar
  • Away
  • Administrator
  • Administrator
  • Posts: 5945
  • Karma: 118
  • Thank you received: 550

MarioPuco replied the topic: list of countries, states and cities used

Hi,

I understand now.
Let me research this and will get back to you ASAP.

Regards,
Mario

Satisfied with our Support ?
PayPal Tip
===============================================
Need to renew Pro Support?
Buy Here!
===============================================
Satisfied?
Consider a membership!
===============================================
Like us on Facebook
===============================================
#219408
  • Posts: 50
  • Thank you received: 2

Akbartus replied the topic: list of countries, states and cities used

Dear Mario,

Thank you so much. Looking forward to your reply.

With kind regards,
Akbartus
#219413
  • Posts: 673
  • Karma: 32
  • Thank you received: 66

JulianGracin replied the topic: list of countries, states and cities used

Hi,

Your problem is related to the check that Content Builder implements. It doesn't allow the saving of data for select lists and such, if that value is not present in the database. For example, if you have a select list with preset options, like this:

0;Title 1;value1
0;Title 2;value2
0;Title 3;value3


And, while editing a record or creating a new one, you use Javascript to change the value of that Select list to value4, Content Builder will not store that value to the database.
The same is also applied to the two select list in the form you are using: CselCountry and CselState.The CselRegion is not affected by this since it already has values set. These two list have nothing set as default values, but instead, are being populated based on the selection on the previous lists. So, when you are saving the record with a certain selection, the CB won't save that data because that list has no default values.
On the other hand, Breezing Forms doesn't do that. It saves anything.

So, to get around this, there are a few things to do:

First, you will need to add this piece of code to the Form -> Advanced -> More Options -> Submit Pieces -> End Submit and Click on Custom radio button. There, paste in the following code:
$this->execPieceByName('ff_InitLib');

$recId = JRequest::getVar('record_id');

ff_updateCustom($this->submitdata, 'CselCountry', $recId);
ff_updateCustom($this->submitdata, 'CselState', $recId);

// This function will take care of updating the #__facileforms_subrecords table with the proper values
// - for $submits  passin $this->submitdata
// - for $elementName  pass in the name of the element whose value you wish to update
// - $recId takes the record id of the element beign edited. If it is not set, it a new record and there is nothing update in the table
function ff_updateCustom($submits, $elementName, $recId) {
  $db = JFactory::getDBO();

  foreach ($submits as $sub) {
    if ($sub[1] == $elementName) {

      $inputName = $sub[1];
      $inputValue = $sub[4];
    
      $inputElement = $sub[0];
      $inputTitle = $sub[2];
      $inputType = $sub[3];

      if ($recId != '') {
        $db->setQuery("Select id from #__facileforms_subrecords Where name = '$inputName' And record = $recId ");
        
        $res = $db->loadResult();
        if ($res) {
          $db->setQuery("Update #__facileforms_subrecords Set value = '$inputValue' Where name = '$inputName' And record = $recId ");
        } else {
          $db->setQuery("Insert into #__facileforms_subrecords ( record, element, title, name, type, value ) values ( $recId, $inputElement, '$inputTitle', '$inputName', '$inputType', '$inputValue' ) ");
        }

      } else {
        $db->setQuery("Select MAX(record) From #__facileforms_subrecords");
        $targetId = $db->loadResult();
        $db->setQuery("Select id from #__facileforms_subrecords Where name = '$inputName' And record = $targetId ");
        if ($db->loadResult() == '') {
          $db->setQuery("Insert into #__facileforms_subrecords ( record, element, title, name, type, value ) values ( $targetId, $inputElement, '$inputTitle', '$inputName', '$inputType', '$inputValue' ) ");
        }
      }
      $db->query();
      return;
    }
  }
}

If you are going to change the names of the elements (currently: CselCountry and CselState), you will need to change the following lines at the beginning of the code to match the new names you have chosen for your elements:

ff_updateCustom($this->submitdata, 'CselCountry', $recId);
ff_updateCustom($this->submitdata, 'CselState', $recId);


This part will take care of saving the record data to the database.

Now, loading the correct list states when editing the record you will need to paste the following code in the Region element's Initscript. Select the Custom for Type, and check the Form Entry checkbox. The code is:
function ff_CselRegion_init(element, condition) {
    switch (condition) {
        case 'formentry':

        var regionElementName = 'CselRegion';
        var countryElementName = 'CselCountry';
        var stateElementName = 'CselState';

        jQuery(function () {

          jQuery('[name="ff_nm_CselRegion[]"]').trigger('change');

          if (jQuery('[name="cb_record_id"]').val() != 0) {

            jQuery.post( '<?php return JUri::root(); ?>index.php', {
              option: 'com_breezingforms',
              ff_form:ff_processor.form,
              format: 'html',
              ItemId: 0,
              record: jQuery('[name="cb_record_id"]').val(),
              elementName: countryElementName

            }, function (data) {

              ff_getElementByName(countryElementName).value = data;

              jQuery('[name="ff_nm_' + countryElementName + '[]"]').trigger('change');

              jQuery.post( '<?php return JUri::root(); ?>index.php', {
                option: 'com_breezingforms',
                ff_form:ff_processor.form,
                format: 'html',
                ItemId: 0,
                record: jQuery('[name="cb_record_id"]').val(),
                elementName: stateElementName
              }, function (data) {

                ff_getElementByName(stateElementName).value = data;

              });
            });
          }
          });
          break;
          default:;
        } // switch
      } // ff_CselRegion_init

As before, if you are using different names for your elements, change the following:

var regionElementName = 'CselRegion';
var countryElementName = 'CselCountry';
var stateElementName = 'CselState';


To match you element names.

This should solve the issues you were facing. Let me know if everything is working as expected.


Regards,
Julian

=========================================
Need to renew Pro Support?
Buy Here!
=========================================
Satisfied?
Consider a membership!
=========================================
Like us on Facebook
=========================================
Support Crosstec and get ALL EXTENSIONS and professional support for just $5
Here!
#219434
  • Posts: 50
  • Thank you received: 2

Akbartus replied the topic: list of countries, states and cities used

Dear Julian,

Thank you very much. Excellent solution. Now everything works perfectly.

I think this solution deserves being integrated into the sample form "countrySelectQuick" + an instruction should be provided in it.

Have a wonderful day.

With kind regards,
Akbartus
#219447
  • Posts: 50
  • Thank you received: 2

Akbartus replied the topic: list of countries, states and cities used

Dear Julian,

One more, last question.

What if the second list (Country) is multi-select list, i.e. allows selecting 2 or more countries. Will it show them as well (in edit mode and CB list view) or there is a need for additional coding?

Thank you.
#219450
Moderators: ForumSupporttomeperica
Time to create page: 0.113 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