FormIt Integration Options: Make Form Submissions Easily Accessible to Client Only

Awesome. Great to hear we’re on the right tracks. I’ll post a snippet you can use to decode the JSON later on today when I’ve got some time.

If you want to give the snippet a shot yourself have a look at https://docs.modx.com/xpdo/2.x/class-reference/xpdoobject/field-accessors/fromjson

Basically you want the snippet to read the JSON of the [[+value]] placeholder (either call the snippet directly Or you could write this as an output modifier), then foreach loop through the object to output a string as readable data. I can’t quite remember how to format the string correctly as any newline will trigger an error in your tsv file. I’ll work through an idea and post

1 Like

This is a terrific lead. Thank you so much for sending. I am working on this this morning. I had done some googling last night for decoding JSON and felt like I was going down a rabbit hole.

1 Like

Ok, so i’ve been working on a simple snippet that will handle the conversion to CSV for you. It’s not elegant and full of holes, but it will do the job for you. Create a new snippet and call it in your resource (blank template with richtext false). Best to use CSV content type for the resource, but you can use HTML, either way =ImportFeed will work on both.

You’ll need to update the table name to match yours ( modxvs_formit_forms)
Also note that this only works for non-encrypted forms… i’ll continue working on getting a decrypt to work as it may help someone else.

1 Like

Got it to load. I removed the explanation mark from the snippet call. Two columns are results from radio buttons… essentially Yes or No is the available response. Those are populated with the word “Array”. I thought there was a cell that contained both first and last name, but it turns out that field was for the user to insert another persons first and last name in a single field — so all good there. This is awesome. Thank you.

2 Likes

No worries. Glad you got it to work :smiley:

When I get sometime I’ll see if I can hook into FormIts Decrypt Class to a version of the above can be used with encrypted forms.

On a side note, I highly recommend you find a way to restrict access to the resource. Last thing you want is personal data being held on a publicly accessible URL. You can mitigate this by giving the alias a random string i.e. 706b16b2fb732ab6079a10fea61d078b or use a snippet like below…

<?php 

$aKey = "706b16b2fb732ab6079a10fea61d078b";

if( !isset($_GET['key']) && $_GET['key'] != $aKey ) {
  $modx->sendUnauthorizedPage();
}

Add this snippet to the top of your resource page, then access the data by visiting https://yoursite.com/data.csv?key=706b16b2fb732ab6079a10fea61d078b

NOTE: The above code hasn’t been tested and there is probably a better way of doing it. I just want to give you something more to think about :smiley:

1 Like

Thank you so much for your help on this. I was kind of concerned about personal data and the public aspect. The random key idea is perfect.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.