MIGX Formit2Resource Entry

Greetings Wise Ones,

I wish to know how to reference a specific formtab of a master tv within a formit call. I AM able to do this successfully with a Numerical Template Variable directly associated to the Template I’m using. I get a clean numerical entry into a simple TV on resource creation. However I’m not sure how to specifically reference the same TV when it is included in a Master MIGX config formtab. I wish to insert several 3 digit temperature values into a migx tv grid on Resource CREATE from a front end formIt.

The main TV with the MIGX config is:
temp_core

the formtab field is:
tmp1

the formtab field references the TV:
temp_one number

The FormIt Call:
[[FormIt?
&hooks=FormIt2Resource
&preHooks=Resource2FormIt
$resource2formitfields=pagetitle,content, temp_core.tmp1
]]

the form HTML in question:

<label for="temperature1">

tmp1: [[fi.error.temp_core.tmp1]]

The question really is does [[+fi.temp_core.tmp1"]] reference the tmp1 field in the MIGX table temp_core on the Template I’m using?

I referenced the following thread which didn’t seem to provide the solution to my specific use.
https://forums.modx.com/thread/?thread=54204&i=1&page=

I am fairly certain this question has a simple solution which eludes me… Let me know if you need more data.

you will need to save MIGX-items in a specific json-format into the MIGX-TV

maybe that helps to get the idea

So based on your clue and some googs I am thinking I can augment the hook script to grab the json array corresponding to the TV I’d like to edit, build my new array to push on, and then re-encode the json before overwriting the original value. Adding these lines before the document save in FormIt2Resource.
$tempArray=array(json_decode($doc->get(‘temp_core’)));
$tempArrayLast=end($tempArray);
$migxid=$tempArray(‘MIGX_id’)+1;

$entryDate=new Date("Y/m/d H:i:sa",now());

$newEntry=array("MIGX_id"=>$migxid,"temp1"=>get('temperature1'),"temp2"=>55,"tempTime"=>$entryDate);

$newEntry=array_push($tempArray,$newEntry);
$newEntry=json_encode($newEntry);
$doc->set('temp_core', $newEntry);

$doc->set('template', '11');
$doc->save();

Atrocious?
is this generic method useful in modx / migx specifically. I didn’t see that you included the link there to that older post, I will see how far off I was.

Give me a bit to tweek my monstrocity to reflect these clean examples

the last item has not allways the max MIGX_id, so you will need to loop over all items to get the next next MIGX_id like in my example.

If this will get a lot entries, perhaps it would be a good idea to store them into a custom table instead of a MIGX TV

Much appreciated, I had some wonderful realizations about the backend process by attempting this senario with your advice. now it is apparent to me, the database solution is critical. Thank you. I created a new table in mysql and then attempted (without success) to autmoatically create the schemas and configs with db2formit as well as an attempt with createXpdoClasses. I’m in the process of following Bobs guide for custom database. I can tell each path I choose will require a great deal of learning, which I expect is inevitable. So in the mean time, do you have a prefered method for adding a custom database? Is the bobs guide timely?

So it seems there are multiple ways to accomplish this integrating a custom database table, so my question is there a most common approach I should focus on. Any additional tips to keep me on the right track?

usually, its done the other way arround. First create the db schema and let modx create the tables

maybe interesting:


and there is this new package in the works:

2 Likes

Wow how’d I miss this guy. Bass ackwards as usual I am. I must prefer the hard way. This is the most productive conversation I’ve had in months, thank you so much for your contributions. I’ll dive in and share my results.