I’m stuck with the problem of showing the output of a remote service call. I defined an action that calls the service, but I fail to understand how to display the result. The only guidance I found, so far, comes from the Injection plugin, but it’s quite convoluted. There has to be an easier way to display results. E.g. stick the output into a div with a certain id.
One path of investigation has been AJAX. But the service is server-side, and I don’t want to call the service from the client side so AJAX doesn’t doesn’t help.
Any clues are highly appreciated.
One approach is to create a plugin doing custom form processing of your form.
In the onFormProcessed() function you can do the call to the remote service using the submitted form data. Once you have received the service response you can put the results in a PHP variable.
To pass it on as a Twig variable see Output some PHP code result in a Twig template.
Finally in your plugin, and from within
onFormProcessed(), you can tell Grav to output your page, named for example
results, which uses the template you used in the previous step:
It might even work with the page you set in the display action of the form. In that case you don’t need to redirect from your plugin but let the Form plugin do that.