I'm quite new to UF and I'm developing a web tool based on the included tooling. I already read all the tutorials carefully and also mostly understand the basic workflows between PHP, Twig, Slim and JQuery. Even though I'm not a professional in all of these technologies and therefore I have two questions, which hold me a little back on developting the stuff that I want to achieve. Please don't blame me if the questions are some kind of stupid.
1.) What is the "right" / "expected" way to pass parameters back to an initial page during reloading the page with JQuery and after POSTing some data to an endpoint. To make it more clear here a little example:
- Site based on Twig is loaded
- Some data is POSTed to an endpoint and processed (including a parameter needed after reloading the inital page)
- JQuery initiates the routing (reloading)
- initial Site is reloaded based on twig (here I need the parameter)
It is no global required parameter so i guess a session variable would not be an adequate option. Also putting it in the url path (not query param) would also not be the proper solution because the parameter is only related to the view and not directly to the object processed in this route.
Currently I use a query parameter, which I pass with the URL on reload. Is there a better way of handling the needed funcionality?
function(data, statusText, jqXHR) {
var cSelect = $('#input_group').val();
window.location="{{site.uri.public}}/states?c=" + cSelect;
}
2.) The second question is a little more diffuse because I don't exactly know how to do this. What would be the best way of fetching data on a page in dependence of an user interaction e.g. an option in a select-tag is chosen and I want to update the option elements in an other select-tag in dependence.
Please correct my thoughts if I'm wrong. I would build up a JQuery routine which reacts on changes of the first select-tag, accesses a specific route to fetch the data and exchange the existing option's with the new fetched data. Would this be the correct approach? It would make me really really happy if someone can attach some basic code for the JQuery but especially for the Controller and in which way I can correctly pass back the information from php to Javascript (format of the response? json?). Reloading a simple string would be enough, everything else I can figure out myself just need some kind of basic information how to do this right.
I know how to do both of this things, but I want to do it correctly based on the UF included tooling. Therefore my question and I also think this would help other people who are new to UF and the included tools.