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

Calc element outside repeat group

mirceat

Member
Hello,

I'm looking for a snippet of code or an idea about how to display the values retrieved from a repeat group available in a multi page form.

Think of a shopping cart that include buyers data, buyers products (this is the repeat group), shipping and payment methods, each group visible on a single page in form.

On the checkout page (also a single page) i have a calc element that should display the values from the repeat group. i searched the forum to find some help, but i don't know why i can't make it work.

The only way i can display something in the calc element is by using the placeholder, but it will display only the selection from the first group. I tried this code, but i get the message 'undefined'..
Code:
 $vals='{aplicatii_comenzi_telefoane_467_repeat___categorie_produs}';
$selected = array();
forech ($vals as $val) {
if ($val != 0) {
$selected[] = $val;
}
}
$msg = implode("\n", $selected);
return $msg;
I also tried this code, but for this i don't get any value, might be because i don't have Fabrik 3.2 installed (the update broke my website so i had to revert it to a stable version for this website)
Code:
 $foo = FabrikWorker::JSONtoData($data['aplicatii_comenzi_telefoane_467_repeat___categorie_produs'], true);
return implode(',', $foo);
Thank you
 
What is $vals set to after that first line in your first chunk of code?

Add ...

var_dump($vals);exit;

... as the the second line, and submit. Let me know what it dumps out.

You may have to load up the form in the page before you add that code, to avoid having it run on page load and prevent you from loading the page.

-- hugh
 
Code:
array(82) { ["aplicatii_comenzi_telefoane___id"]=> string(0) "" ["aplicatii_comenzi_telefoane___id_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___date_time"]=> string(19) "2015-03-25 09:09:43" ["aplicatii_comenzi_telefoane___date_time_raw"]=> string(19) "2015-03-25 11:09:43" ["aplicatii_comenzi_telefoane___nr_comanda"]=> string(0) "" ["aplicatii_comenzi_telefoane___nr_comanda_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___adaugat_de"]=> string(8) "Mircea T" ["aplicatii_comenzi_telefoane___adaugat_de_raw"]=> string(2) "42" ["aplicatii_comenzi_telefoane___modificat_de"]=> string(8) "Mircea T" ["aplicatii_comenzi_telefoane___modificat_de_raw"]=> string(2) "42" ["aplicatii_comenzi_telefoane___nume_agent"]=> string(0) "" ["aplicatii_comenzi_telefoane___nume_agent_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___cod_agent"]=> string(5) "false" ["aplicatii_comenzi_telefoane___cod_agent_raw"]=> string(5) "false" ["aplicatii_comenzi_telefoane___partener_agent"]=> string(0) "" ["aplicatii_comenzi_telefoane___partener_agent_raw"]=> array(1) { [0]=> string(0) "" } ["aplicatii_comenzi_telefoane___regiune_agent"]=> string(14) "--selecteaza--" ["aplicatii_comenzi_telefoane___regiune_agent_raw"]=> string(1) "0" ["aplicatii_comenzi_telefoane___echipa_agent"]=> string(14) "--selecteaza--" ["aplicatii_comenzi_telefoane___echipa_agent_raw"]=> string(1) "0" ["aplicatii_comenzi_telefoane___tip_activare_agent"]=> string(14) "--selecteaza--" ["aplicatii_comenzi_telefoane___tip_activare_agent_raw"]=> string(1) "0" ["aplicatii_comenzi_telefoane___id_order_new_pos"]=> string(0) "" ["aplicatii_comenzi_telefoane___id_order_new_pos_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___denumire_firma"]=> string(0) "" ["aplicatii_comenzi_telefoane___denumire_firma_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___cui_client"]=> string(0) "" ["aplicatii_comenzi_telefoane___cui_client_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___persoana_decizie"]=> string(14) "--selecteaza--" ["aplicatii_comenzi_telefoane___persoana_decizie_raw"]=> string(1) "0" ["aplicatii_comenzi_telefoane___nume_prenume_client"]=> string(0) "" ["aplicatii_comenzi_telefoane___nume_prenume_client_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___adresa_livrare_client"]=> string(0) "" ["aplicatii_comenzi_telefoane___adresa_livrare_client_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___oras"]=> string(0) "" ["aplicatii_comenzi_telefoane___oras_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___judet_sector"]=> string(0) "" ["aplicatii_comenzi_telefoane___judet_sector_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___cod_postal"]=> string(0) "" ["aplicatii_comenzi_telefoane___cod_postal_raw"]=> string(0) "" ["join___994___aplicatii_comenzi_telefoane_467_repeat___id_0"]=> string(0) "" ["join___994___aplicatii_comenzi_telefoane_467_repeat___id_0_raw"]=> string(0) "" ["join___994___aplicatii_comenzi_telefoane_467_repeat___parent_id_0"]=> string(0) "" ["join___994___aplicatii_comenzi_telefoane_467_repeat___parent_id_0_raw"]=> string(0) "" ["join___994___aplicatii_comenzi_telefoane_467_repeat___categorie_produs_0"]=> string(12) "Data devices" ["join___994___aplicatii_comenzi_telefoane_467_repeat___categorie_produs_0_raw"]=> string(12) "Data devices" ["join___994___aplicatii_comenzi_telefoane_467_repeat___clasa_terminale_0"]=> string(1) "0" ["join___994___aplicatii_comenzi_telefoane_467_repeat___clasa_terminale_0_raw"]=> string(1) "0" ["join___994___aplicatii_comenzi_telefoane_467_repeat___produs_comanda_0"]=> string(0) "" ["join___994___aplicatii_comenzi_telefoane_467_repeat___produs_comanda_0_raw"]=> string(0) "" ["join___994___aplicatii_comenzi_telefoane_467_repeat___nr_telefon_comanda_0"]=> string(0) "" ["join___994___aplicatii_comenzi_telefoane_467_repeat___nr_telefon_comanda_0_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___discount_comanda"]=> string(2) "Nu" ["aplicatii_comenzi_telefoane___discount_comanda_raw"]=> string(2) "Nu" ["aplicatii_comenzi_telefoane___valoare_discount"]=> string(0) "" ["aplicatii_comenzi_telefoane___valoare_discount_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___metoda_plata"]=> string(0) "" ["aplicatii_comenzi_telefoane___metoda_plata_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___comentarii_comanda"]=> string(0) "" ["aplicatii_comenzi_telefoane___comentarii_comanda_raw"]=> string(0) "" ["aplicatii_comenzi_telefoane___sumar_comanda"]=> string(11) "Smartphones" ["aplicatii_comenzi_telefoane___sumar_comanda_raw"]=> string(11) "Smartphones" ["join"]=> array(1) { [994]=> array(6) { ["aplicatii_comenzi_telefoane_467_repeat___id"]=> array(1) { [0]=> string(0) "" } ["aplicatii_comenzi_telefoane_467_repeat___parent_id"]=> array(1) { [0]=> string(0) "" } ["aplicatii_comenzi_telefoane_467_repeat___categorie_produs"]=> array(1) { [0]=> array(1) { [0]=> string(14) "Data%20devices" } } ["aplicatii_comenzi_telefoane_467_repeat___clasa_terminale"]=> array(1) { [0]=> array(1) { [0]=> string(1) "0" } } ["aplicatii_comenzi_telefoane_467_repeat___produs_comanda"]=> array(1) { [0]=> array(1) { [0]=> string(0) "" } } ["aplicatii_comenzi_telefoane_467_repeat___nr_telefon_comanda"]=> array(1) { [0]=> string(0) "" } } } ["fabrik_vars"]=> array(1) { ["querystring"]=> array(2) { ["aplicatii_comenzi_telefoane___access"]=> string(0) "" ["aplicatii_comenzi_telefoane___partener_agent"]=> string(0) "" } } ["aplicatii_comenzi_telefoane_467_repeat___id"]=> string(0) "" ["aplicatii_comenzi_telefoane_467_repeat___parent_id"]=> string(0) "" ["aplicatii_comenzi_telefoane_467_repeat___categorie_produs"]=> string(12) "Data devices" ["aplicatii_comenzi_telefoane_467_repeat___clasa_terminale"]=> string(14) "--selecteaza--" ["aplicatii_comenzi_telefoane_467_repeat___produs_comanda"]=> string(0) "" ["aplicatii_comenzi_telefoane_467_repeat___nr_telefon_comanda"]=> string(0) "" ["option"]=> string(10) "com_fabrik" ["format"]=> string(3) "raw" ["task"]=> string(17) "plugin.pluginAjax" ["plugin"]=> string(4) "calc" ["method"]=> string(9) "ajax_calc" ["element_id"]=> string(4) "6741" ["formid"]=> string(3) "261" ["Itemid"]=> string(4) "1353" ["view"]=> string(6) "plugin" ["rowid"]=> string(1) "0" ["aplicatii_comenzi_telefoane___access"]=> array(1) { [0]=> string(0) "" } ["aplicatii_comenzi_telefoane___access_raw"]=> array(1) { [0]=> string(0) "" } }
 
it's a database join, no multiselect (dropdown), in a repeat group
Please note that in the repeat group there are also two textfields and one dropdown, i need to take all those fields (+other from other groups, single instance) and display a order summary using the calc element.
Also, should be a multiplage form, but for the moment i test it in a single page form.
 
OK ... then this should get you the value (well, the label) ...

$categorie_produs = $data['aplicatii_comenzi_telefoane_467_repeat___categorie_produs'];

... which is going to be an array, with each of the repeat group instances. And each of those is going to be an array with a single value - even if your join is not a "multi select" type, which need to be arrays to hold the multiple selections, the data will still be represented as an array, for internal consistency in the code, so join results are always arrays.

So, if you wanted to return that as a line seperated string (as per your OP) ...

Code:
$categorie_produs = $data['aplicatii_comenzi_telefoane_467_repeat___categorie_produs'];
$results = array();
foreach ($categorie_produs as $key => $val) {
   $results[] = $val[0];
}
return implode("\n", $results);

If you need to add in other values from the same repeat instance, you can use the $key from that foreach. So (and I'm just making an example up) if you had a categorie_price you wanted to show with it, you might do ...

Code:
$categorie_produs = $data['aplicatii_comenzi_telefoane_467_repeat___categorie_produs'];
$categorie_price = $data['aplicatii_comenzi_telefoane_467_repeat___categorie_price'];
$results = array();
foreach ($categorie_produs as $key => $val) {
   $results[] = $val[0] . ': ' $categorie_price[$key];
}
return implode("\n", $results);

Just use that $data var dump to work out if the data you need is in a simple string format, or an array of strings.

-- hugh
 
Hugh, your code should work on the fly(ajax calculation) for a calc element or should i use the option "Calc on save"? Also, it will work with Fabrik 3.0.9?

Unfortunately, i can't make it work with any of those option, i don't get any value in the calc element. Using var_dump($data) will show NULL when i use the option "Ajax calculation" and if i use "Calc on save" will return an array with the first value of the databasejoin element, but using the code from above will not return any response. I tried with multipage form and with single page form, same problem.

How safe is to upgrade from 3.0.9 to 3.3.1 having PHP version 5.3.3 (the server admin don't want to make the upgrade to a new version as long RedHat doesn't released a newer version) and Joomla 2.5.28 (also non upgradable because of PHP version)?

P.S: if you want, i can provide some login data for this website. It's a live site, but the form is not available to users.

Thank you
 
Hmm, I keep forgetting this is 3.0.9. Nope, it probably won't work. We fixed a lot of issues with the calc element in 3.1, and in the way data is represented between submission and rendering. And no, you probably won't be able to run J! 3.x and Fabrik 3.3.1 with PHP 5.3.3. I'm not even sure J! 3.4 will install with it.

While I understand a system admin's reluctance to upgrade, PHP 5.3 is now 6 years old, and was officially end of lifed in Aug of last year. So you are going to find it really hard to move forward. It's one thing maintaining a stable server, but you have to balance that with keeping your applications up to date. Which you simply cannot do if you are stuck with PHP 5.3. Which is arguably more of a risk than updating Centos / RHEL to at least 5.4, as it means you are now running end of lifed versions of not just PHP, but J! and Fabrik, and every other PHP / MySQL app you are running, which raises it's own set of security issues.

The PHP 5.3 to 5.4/5 update is a thoroughly safe and well understood update, using trusted repos like Remi, and an easy tweak to Centos's yum repository config. I've been running RHEL / Centos since 1.x, it's my default flavor of Linux, I've been a UNIX / Linux systems admin for 30+ years ... and the PHP / MySQL update is the first thing I do on all my Centos installs.

I'm not sure what your options are, but it may be time you considered moving your app to a different server. The longer you stay stuck on J! 2.5, the more you get backed in to that "legacy" corner, the less support you'll get (we are about to announce the official end of life of 3.0) and the harder your update is going to be.

Anyway ... I think your better bet is to look at doing this as a PHP form submission plugin, rather than in a calc element, and / or put some energy in to getting moved to a new server ... and have a Stern Talk with the systems admin about running end-of-lifed (and hence more vulnerable) software.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top