TOPIC:

Import data from one Breezing Form into another 6 years 5 months ago #108896

  • Topic Author
  • bussupbf
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 45
  • Thanks: 0
I found a few examples that didn't exactly do this but did something similar. I see others are trying to do the same thing I did, so hopefully this will help them.

I have several forms. I take data that was entered by a user into one form (actually several forms) and use that to prefill elements in a new form.
I have only one record per form for each user. If you allow your users to create multiple records for one form, you need to make a modification (I pointed that out below the first time that code is encountered).

Using the example below as a guideline, you can make modifications. For example I gather information that the same user put in the other form. If I filled up the other form, I could just hardcode the user_id below to my UserName to pull up that information.

In the example below, I use <your….> for generic names, so replace that entire text including the < > with the name for your variables/items

There are 2 parts to this process: Part 1 gets the data from the other form. Part 2 puts the data in the elements where you want the data.
Part 1:

Go to Form you want to import data to (not the one you are getting data from) => Advanced tab => more options => Form Pieces => Before Form. Place the following in that section.
Note: I got errors if I put the comments in (maybe because they are not starting at the far left), I store and edit my code in a spreadsheet, so I put the comments in the 2nd column and only copy the first column into the before form section.

$this->execPieceByName('ff_InitLib');
// I don’t know why specifically $database and $record are used, but there were problems if I tried to make these local variables
// I believe the variables below need to be unique from other variables or element names
global $database, $record, $<your variable #1>, $<your variable #2>, $<your variable #3>;
// Use the user id of visited user to find the records that belong to that user
$user = Jfactory::getUser()->get('id');
// name of form want data from
$formname = "<form you want data from>";
// get record number that belongs to the visiting user and the form you want data from
$database->setQuery("
SELECT *
// I used jos_facilieforms_records. You may have a different prefix (check the database tables for your Joomla table), you can also use #__josfacileforms_records - I think that is the correct syntax (# with two _) but I am not double checking this at this time.
FROM jos_facileforms_records
WHERE user_id = '$user'
AND name = '$formname'
");
//Assign those records to a local variable.
$row = $database->loadObjectList();
// Note, we use only one record per user per form, if you have more than one record per form per user you need to use an array to get the other records, there are examples in the forum
$record = $row[0];

// get first variable you want from the other form
$database->setQuery("
SELECT *
FROM jos_facileforms_subrecords
WHERE record = '$record->id'
// in the sentence below, you need to put in the exact name of the element in the other form that you want to get data from
AND name = '<element name in the form you are getting the data from>'
");
$row = $database->loadObjectList();
// below, you use the global variable you declared above to store the info in so anywhere in your form has access to it
$<your variable #1> = $row[0];

// get the second variable you want from the other form
$database->setQuery("
SELECT *
FROM jos_facileforms_subrecords
WHERE record = '$record->id'
// in the sentence below, you need to put in the exact name of the element in the other form that you want to get data from
AND name = '<element name in the form you are getting the data from>'
");
$row = $database->loadObjectList();
$<your variable #2> = $row[0];

// now I want to change the form where I want to get data from
$formname = "<another form you want data from>";
// get record number that belongs to the visiting user and the form you want data from
$database->setQuery("
SELECT *
FROM jos_facileforms_records
WHERE user_id = '$user'
AND name = '$formname'
");
//Assign those records to a db variable.
$row = $database->loadObjectList();
$record = $row[0];

// get first variable you want from this second form you are getting data from
$database->setQuery("
SELECT *
FROM jos_facileforms_subrecords
WHERE record = '$record->id'
// in the sentence below, you need to put in the exact name of the element in the other form that you want to get data from
AND name = '<element name in the form you are getting the data from>'
");
$row = $database->loadObjectList();
$<your variable #3> = $row[0];

Make sure you do a save.


Part 2:
Then go to the form elements
Now you have 3 global variables you can use in your forms. In the element you want the data to appear in, in the value field, put in the following
<?php global $<your variable #1>; return $<your variable #1>->value;?>
<?php global $<your variable #2>; return $<your variable #2>->value;?>
<?php global $<your variable #3>; return $<your variable #3>->value;?>


My exact code - Note I reduced this so only 6 data items are being gotten (3 each from 2 different forms) to make it easier to follow.

This takes values that were entered in the forms:
blc24tracking - elements (blcteam, smallteam, lcwpledge)
blc24Week3 - elements (camochal1descweek3, camochal2descweek3, camochal3descweek3)
and puts them into the corresponding global variables:

blcteam => $blcteamweek4,
smallteam => $smallteamweek4,
lcwpledge=> $lcwpledgeweek4,
camochal1descweek3 => $camochal1descweek4,
camochal2descweek3 => $camochal2descweek4,
camochal3descweek3 => $camochal3descweek4.

This is the form name I am putting this code (and data) into: blc24Week4

In Form, Advanced tab, more options, Form Pieces, Before Form:
Do not copy the comments
$this->execPieceByName('ff_InitLib');
global $database, $record, $blcteamweek4, $smallteamweek4, $lcwpledgeweek4, $camochal1descweek4, $camochal2descweek4, $camochal3descweek4;
// Use the user id of visited user to find the records that belong to that user
$user = Jfactory::getUser()->get('id');
// name of form want data from
$formname = "blc24tracking";
// get record number for visiting user that goes with the form want data from
$database->setQuery("
SELECT *
FROM jos_facileforms_records
WHERE user_id = '$user'
AND name = '$formname'
");
//Assign those records to a db variable.
$row = $database->loadObjectList();
$record = $row[0];

// get blcteam
$database->setQuery("
SELECT *
FROM jos_facileforms_subrecords
WHERE record = '$record->id'
AND name = 'blcteam'
");
$row = $database->loadObjectList();
$blcteamweek4 = $row[0];

// get smallteam
$database->setQuery("
SELECT *
FROM jos_facileforms_subrecords
WHERE record = '$record->id'
AND name = 'smallteam'
");
$row = $database->loadObjectList();
$smallteamweek4 = $row[0];

// get lcwpledge
$database->setQuery("
SELECT *
FROM jos_facileforms_subrecords
WHERE record = '$record->id'
AND name = 'lcwpledge'
");
$row = $database->loadObjectList();
$lcwpledgeweek4 = $row[0];

// I change the name of form want data from here
$formname = "blc24week3";
// get record number for visiting user that goes with the form want data from
$database->setQuery("
SELECT *
FROM jos_facileforms_records
WHERE user_id = '$user'
AND name = '$formname'
");
//Assign those records to a db variable.
$row = $database->loadObjectList();
$record = $row[0];

// get last week's info for camochal1descweek4
$database->setQuery("
SELECT *
FROM jos_facileforms_subrecords
WHERE record = '$record->id'
AND name = 'camochal1descweek3'
");
$row = $database->loadObjectList();
$camochal1descweek4 = $row[0];

// get last week's info for camochal2descweek4
$database->setQuery("
SELECT *
FROM jos_facileforms_subrecords
WHERE record = '$record->id'
AND name = 'camochal2descweek3'
");
$row = $database->loadObjectList();
$camochal2descweek4 = $row[0];

// get last week's info for camochal3descweek4
$database->setQuery("
SELECT *
FROM jos_facileforms_subrecords
WHERE record = '$record->id'
AND name = 'camochal3descweek3'
");
$row = $database->loadObjectList();
$camochal3descweek4 = $row[0];


THIS PROVIDES DATA TO PUT IN ELEMENT VALUE FIELDS - using following syntax

<?php global $blcteamweek4; return $blcteamweek4->value;?>
<?php global $smallteamweek4; return $smallteamweek4->value;?>
<?php global $lcwpledgeweek4; return $lcwpledgeweek4->value;?>
<?php global $camochal1descweek4; return $camochal1descweek4->value;?>
<?php global $camochal2descweek4; return $camochal2descweek4->value;?>
<?php global $camochal3descweek4; return $camochal3descweek4->value;?>

Note: Looking at your Joomla Database Tables can be helpful to understand their structure as you write your code.

Go to your hosting site, and go to the database that your Joomla database, then do a phpmyadmin to look at it (your hosting site can help you do this if you don't know how).

When I go into my database it shows choices (to the left) of the database name & information_schema
I expand the database name (click on the +)
then look for <something>_facileforms_records and <something>_facileforms_records. The <something> in my database is jos, so mine are jos_facilieforms_records and jos_facilieforms_subrecords

I click on jos_facilieforms_records
At the top I click on the SQL tab
This query is already filled in:
SELECT * FROM `jos_facileforms_records` WHERE 1
I click the Go button on the bottom right
I get a list of rows. The columns I care about are ID (the record number), Name (the form name), and user name

If I have 2 users that have all filled in each of 3 forms, it looks like: (I made up the ID numbers so I could show them in the subrecords table also, the numbers I used were nnnn where the first nn is the form #, the second nn is the user name #, note I made these up, they will show as a random looking number in your tables, but you want to match this id up to the record in the subrecord)
ID Form User Name
<0101> <formname for form #1> <user name #1>
<0201> <formname for form #2> <user name #1>
<0301> <formname for form #3> <user name #1>
<0102> <formname for form #1> <user name #2>
<0202> <formname for form #2> <user name #2>
<0302> <formname for form #3> <user name #2>

Now I go to jos_facilieforms_subrecords
At the top I click on the SQL tab
This query is already filled in:
SELECT * FROM `jos_facileforms_subrecords` WHERE 1
I click the Go button on the bottom right
I get a list of rows. The columns I care about are record (corresponds to the ID from the records table), name (the element name in the form the record goes to), and the value (the value of the element)

If for each of the forms I have 2 elements, and I had 3 different users, each fill in each of the 3 forms, I would have 18 rows and it would look like:
record name value
<0101> <element name #1 for Form #1 User #1> <element value>
<0101> <element name #2 for Form #1 User #1> <element value>
<0201> <element name #1 for Form #2 User #1> <element value>
<0201> <element name #2 for Form #2 User #1> <element value>
<0301> <element name #1 for Form #3 User #1> <element value>
<0301> <element name #2 for Form #3 User #1> <element value>
<0102> <element name #1 for Form #1 User #2> <element value>
<0102> <element name #2 for Form #1 User #2> <element value>
<0202> <element name #1 for Form #2 User #2> <element value>
<0202> <element name #2 for Form #2 User #2> <element value>
<0302> <element name #1 for Form #3 User #2> <element value>
<0302> <element name #2 for Form #3 User #2> <element value>

Note, your form maybe large or you may have a lot of users, so changing your query to include a where clause so you only search for one record number gotten from the records table will give you the elements of that form, you can also change the clause to include only the names that correspond to the elements you want to look at.

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

Import data from one Breezing Form into another 1 week 3 days ago #246069

  • jpen
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 60
  • Thanks: 0
Thank you for explaining this. Much appreciated.
Hopefully all works, despite time since.
I'm only in need of extracting 2 elements from source form, would I only need the below to
complete the purpose?
thanks.

<?php global $<your variable #1>; return $<your variable #1>->value;?>
<?php global $<your variable #2>; return $<your variable #2>->value;?>

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

Import data from one Breezing Form into another 1 week 3 days ago #246086

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 9774
  • Karma: 167
  • Thanks: 785
Hi,

depends what you mean by source form?

Regards,
Markus

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

Import data from one Breezing Form into another 1 week 3 days ago #246090

  • jpen
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 60
  • Thanks: 0
Thank you Markus.
Source Form, meaning the form from which I am trying to draw the value of an element into a different form and new element in that form.
From the forum post referenced, "import data," I constructed the below but it remains a work in progress, incomplete.
Please bear with me and my negligible coding skills.
Should I name the variables - var1, var2, var3, does that matter?
Thank you for your help.


$this->execPieceByName('ff_InitLib');
global $database, $record, $<your variable #1>, $<your variable #2>, $<your variable #3>;
$user = Jfactory::getUser()->get('id');
$formname = "<baitahook2_formA>";
$database->setQuery("
SELECT *
FROM jos_facileforms_records
WHERE user_id = '$user'
AND name = '$formname'
");
$row = $database->loadObjectList();
$record = $row[0];
$database->setQuery("
SELECT *
FROM jos_facileforms_subrecords
WHERE record = '$record->id'
AND name = '<bah_name>'
");
$row = $database->loadObjectList();
$<your variable #1> = $row[0];

$database->setQuery("
SELECT *
FROM jos_facileforms_subrecords
WHERE record = '$record->id'
AND name = '<balance>'
");
$row = $database->loadObjectList();
$<your variable #2> = $row[0];


then from within the two elements Ive created in my form, I put in either of the two elements created:

<?php global $<var1>; return $<var1>->value;?>
<?php global $<var2>; return $<var2>->value;?>

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

Import data from one Breezing Form into another 1 week 3 days ago #246091

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 9774
  • Karma: 167
  • Thanks: 785
yeah, you can give them these names, you basically replace everything with the brackets, so they look like thos

$var1
$var2

<?php global $var1; return $var1->value;?>
<?php global $var2; return $var2->value;?>
The following user(s) said Thank You: jpen

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

Import data from one Breezing Form into another 1 week 2 days ago #246094

  • jpen
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 60
  • Thanks: 0
What's curious to me.
When I review the jos_facileforms_records in phpMyAdmin, I find my record(s), but no element factor, "balance," from which I'm trying import to in the pre form script..?
Thanks.

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

Moderators: ForumSupport
Time to create page: 0.053 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

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

breezingforms.eddy-vh.com

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

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