• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

populating multiple lists at the same time

enzo2016

Member
Hi,
I have three forms:
country = country field
region = country databasejoin and region field
town = region databasejoin and town field

I would need to populate these three lists through only one form. So this form should allow to create countries, region and towns. I know that the join feature could help, but the difficulty is that each country includes regions and regions include towns, so the cascading dropdown would be needed too.
Please could you help me to explain how to build the form allowing to add these three fields?

Thanks

Enzo
 
Does it exist a button which allows to record the fields of a group before subscribing the whole form (through the final "Save" button)?
In other words a button working as intermediate "Save" button because it should record the fields before recording the next group fields.

Thanks.

Enzo
 
When I do an "Apply button", it is reffered to the whole form. It could be ok because the Apply button could trigger the autofill for an element. I am explaining better this solution:

please assume only 2 lists for simplicity:
country = country field
region = country_id databasejoin and region field

Steps:
1) When the country field is filled, then the Apply button is pressed.
2) When the Apply button is pressed, the field content should be copied through the autofill plugin from the country field (which is into the country list) to the country_id (databasejoin element which is into the region list).

Questions:
1) The videotutorial about the autofill plugin shows the case for a databasejoin element triggering the autofill. Could the autofill plugin be triggered for the click on the Apply button instead of the selecting of a databasejoin element? If it is possible, will i need of a button element plugin or it could work also for the "normal" Apply button which is referred to the whole form?
2) This solution (as shown in step 2) implies the autofill from a field element to a databasejoin element. Is it possible? I am asking for that because the videotutorial doesn't advice the autofill between element of different type.


Thanks

Enzo
 
You have one option. In addition to 3 tables of country, region and town, you have to create one other form with 3 fields of country, region and town. Use php form plugin to insert record of all these fields to other 3 tables. But you have use the IDs of country, region etc in addition to primary id to check if these were already inserted or not.

Sent from my ELUGA Note using Tapatalk
 
Last edited:
Thanks so much Sunit,
in order to run your suggestion, I would use the following procedure:
1) to create a form with 3 elements type 'field': country, region, town;
2) to add a php plugin which includes the following code:
Code:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->insert('tablename')->set('field = ' . $db->quote('bar'))
->set('field2 = ' . $db->quote('{tablename___elementname}');
$db->setQuery($query);
$db->execute();
$id = $db->insertid();

I am not sure it is the correct sample code to add into the php plugin...
 
Last edited:
I unaware what is your table structure but you also have to add 3 validations (separate validation for each table) on insertid with queries in this form to know if there country, region or state exists so that you can get info for each element if this element already exists? You can also refer the Common PHP Task to get the hint on queries.

Your re-usable database structure should be something like below:

Country table
--------------------
ID Country Name

Region table
------------------
ID Region Name Counrtry ID

Town table
--------------
ID Town Name Region ID Country ID


I don't know whether you are testing or trying on country, region or town tables, but I would suggest to import the country region or town database into your fabrik tables as it is a very huge data. But you still want to customise your data by inserting it into fabrik tables you should also confirm, How would you use this data further in your forms. The start point is, you should make your database structure very efficient so that you can re-use or call it anywhere.

Thanks
Sunit
 
Thanks Sunit,
the structure I am using is the following:
country table = id, country field
region table = id, country_id databasejoin and region field
town table = id, region_id databasejoin, town name field

The country field in the country table should have a isuniquevalue validation and this validation should be maybe valid also in the 'add country' table (that is the table where towns, region and country can be created by using only one form). It is not necessary, for my purposes, to have region and towns with unique values in the region table and in the town table. The validation structure I would need: two regions cannot have the same name into the same country. Two towns cannot have the same name into the same region, but two towns with the same name in different regions could exist.
I have already tested the dropdown and cascading dropdown populated by using the three tables (country, region and town specified above) and it works ok.

The problem is to create a unique form where I can populate these three tables. The name of this form could be 'add_country'.
The field 'country' into this form should need an apply button to send it to the country region and to check if it has a unique value.
If it is so, then the region field becomes active...

My purpose is to display the records of these three tables in other forms. these records should be displayed into dropdown and cascading dropdown elements. Please let me know if I answered correctly to your questions or if further information are needed.

Thanks again

Enzo
 
Are you using a pre-populated country, region and town tables in another form or Are you first populating country, region, town tables by form and reusing it in another form?
 
Thanks for the question.
The country, region and town tables is only an example: they are not geographic cities, so I can't use a ready database to export the towns.
The country, region and town tables are not already pre-populated; I need to populate the three tables and reuse them in another form.
 
You have to prepopulate the country table atleast, otherwise no validation on countries.
Now make a form with [country_id databasejoin] & [region field name] and insert the data in region table for [region field name] & [country_id]
Add 2 more fields with [region_id casacadedropdown] & [town name field] and insert the data in town table for [town name field] & [region_id]

No need for validation as the inserted ids are unique because of database join element.

Thanks,
Sunit
 
Last edited:
Add user field and select to record user ID in all tables. Use -1 in menu items for both form and list for all tables. Add insert for current user ID in the existing form into main tables of country, region and town. Now logon into system and start entering the data. Change also some access settings in list for each table. Now check the list, the list will show the data only related to that user.

That's all.

Thanks
Sunit

Sent from my ELUGA Note using Tapatalk
 
Last edited:
Now make a form with [country_id databasejoin] & [region field name] and insert the data in region table for [region field name] & [country_id]
Add 2 more fields with [region_id casacadedropdown] & [town name field] and insert the data in town table for [town name field] & [region_id]

No need for validation as the inserted ids are unique because of database join element.

Sometimes while entering town you may not have region available. In that case you can use [!empty] validation within php form before running insert query in [region_id casacadedropdown] & [town name field] so that these fields can be escaped and only region field name can be insered and further used in filling town data.

The second option is you may select other region for a while and re-edit it with correct data, if you want to keep this table intact also. In that case you have to validate the query by [if this id =id number then empty] so that no double post of region_id in region table.

You may invent various options and try it before finalizing it into production.

Thanks,
Sunit
 
Last edited:
Thanks Sunit,
what do you mean by "add insert for current user ID"?

About the databasejoin filtered only for my records, I was refering only to the form including country, region and town because I would want to reduce the time of filling that form (so the users can choose only among few options into the databasejoin).
The databasejoin and the cascadingdropdown in other forms should display all of the records (not only mine).

Please could you confirm the correctness of the following structure?

1) country table = user, id, country field
2) region table = user, id, country_id databasejoin and region field
3) town table = user, id, region_id databasejoin, town name field
4) add country table = user, id,
[country_id databasejoin connected to the country field of country table] & [region field name]. The join list should insert the data in region table for [region field name] & [country_id]
[region_id casacadedropdown] & [town name field]. The join list should insert the data in town table for [town name field] & [region_id].



Thanks

Enzo
 
You have to insert the user id of the current user into the region and town table, who is logged-on by php form like other insert queries. you can either escape user field in country table as you are putting country data yourself or populate it by your userid.

Do not make the following table:

4) add country table = user, id
as you will use it yourself to pre-populate by country form of

1) country table = user, id, country field

In the case of
The databasejoin and the cascadingdropdown in other forms should display all of the records (not only mine).

you can keep these list views as public in list view settings.

Try and dig - everything is possible. There are various options available in Fabrik.
 
Last edited:
Yes, the country table will be used to add the country, but every user should add the countries (not only me). By writing 'add country' table I meant the unique form where region and towns can be added and connected to a country.

Thanks,
Enzo
 
Hi Sunit,
sorry for my late reply: I couldn't do the tests because the Christmas holidays.
On 14 December you wrote "
Use php form plugin to insert record of all these fields to other 3 tables
Please could you suggest the correct title/s of code into: http://fabrikar.com/forums/index.php?wiki/common-php-tasks/#forms in order to do that? I think it could be the "Insert" title... is it ok or will I need different or additional code in order to insert the 3 fields content to other 3 tables?

Thanks.
Merry Christmas Sunit! Many wishes to you and your family!
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top