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

[SOLVED] Form PHP $formModel->getElementData from calc

Status
Not open for further replies.

bea

Active Member
Hi,
I ran into an issue, which I don't understand.
I've a form PHP to write a new record into a second table with certain conditions.

The value of one of this elements (calc, condition) returns always a wrong value with var_dump (e.g. in database value=3 and in var_dump = 1). There are other elements with similar calc , which work correctly.

I've now changed the script from
PHP:
$losses3_rework_col =$formModel->getElementData('fab_cp1_line_tour___losses3_rework_col',true);
to
PHP:
$losses3_rework_col =$formModel->getElementData('fab_cp1_line_tour___losses3_rework_col'); 
$losses3_rework_col=is_array($losses3_rework_col) ? $losses3_rework_col[0]:$losses3_rework_col;
Why does this element need an array and the others not???
Cheers,
Bianka
 
Usually, elements which are based on the 'elementlist' model (which extends the base 'element' model), like joins, dropdowns, radiobuttons, checkboxes, etc will submit as an array. In general, those are elements which have multiple options (even if you can only select a single one, like a dropdown).

-- hugh
 
Note the "usually". Sometimes the data for those elements may not be an array, particularly when accessing them from the calc element (which might be running on submit, or it might be running on list load or details view load). Which is why you'll see a lot of my example code over the years use that is_array() thing.

-- hugh
 
I don't really get it, but will test in the future with both options...
Many thanks.
Bianka
 
Certain element types submit data as arrays, not single values. Like anything which renders as a dropdown - even if it's a single select dropdown, it could potentially be a multi-select. So the form submits the data as an array, ie. a name that looks like yourtable___yourelement[], with the square brackets on the end, and we simply expect the result to be an array, even if there's only going to be one value.

If it's a single select, you can just grab the first entry from the array, [0]. if it's a multi select, you have to handle dealing with multiple values in the array.

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top