Hi Ben, Thanks for the info. I will check it out. I did recall briefly looking at this but thought you used an Array. Maybe Array/Datastore is the same method in gettig the data?
Hi @ben, So after some head-scratching, I finally manage to de-code how you were using the Datastore/Form and passing the values back to a server action.
I thank you for making available you wCart which although I am not using, it has allowed me to progress my project.
I second this. Spent the last hours trying to figure this out.
I am doing nested inserts. In the same spirit as the store example, (1) you want to POST order_id to the orders table, and (2) POST item_idâs in the Data Store to the items table. From looking through several posts, a lot of people are struggling with this.
In fact why bother with the hidden forms. Why canât we provide a way to populate a data structure, similar to JSON with repeats and nesting. Then create an action to POST the structure to either database or API.
In my experiment till date, I'm still staying with local storage & not using data store for two primary reasons:
"Set" data from server connect: When using a local storage, I can easily set the results of a server connect to the local storage (both same schema) with a single liner like this:
"Post" data to server connect: I'm aware of the hidden field post method, thanks to @ben's amazing tutorials. The problem is, the moment you have more than one level in your data store (array of objects), the hidden field method becomes too cumbersome. I have spent hours making this work when I wanted to post a nested JSON by passionately following @nevil's thread here - Send nested JSON with server-side API
When we talk about "post"ing data store, let's not forget that we might need to post nested schema as well, in which case we are in fact posting "application/json" type.
Later, I just used the below javascript snippet, called it (from a static event) when I had to post nested json back to server, and I got rid of all the multi-dimensional array of hidden form fields.
function post_search_config(event) {
// Sending and receiving data in JSON format using POST method
var xhr = new XMLHttpRequest();
var url = "http://localhost/dmxConnect/api/userprofile/search_config.php";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
var search_config = dmx.parse('local_storage.data');
var data = JSON.stringify(search_config);
xhr.send(data);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
// things to do after getting a response for the json post
dmx.parse('search_orders.load()');
dmx.parse('flow_set_advanced_filtersort.run()');
}
};
}
Anyone wanting to post data store to server connect could use the above js snippet as an alternative to the hidden form fields method!
Yes, I posted about the same thing last week and wasnât able to find this post either. I can invent my own way but would prefer to use a good Wappler way!
What would be great is just one tutorial of what is possible at the code level right now. Reading through and trying to understand everyoneâs different examples is driving me crazy and not giving me an answer!
We have just managed to do this. Will do a write up later. Quite simple, all came down to input names in our circumstance (finally we bound dynamic names to each input using the index). In the Multi-Insert (the array within the SC Action) the ârecord arrayâ variables must be named the same as the local storage items. That is about it⌠And obviously the insert variables must be named the same as the local storage itemsâŚ