Here’s my scenario. I have a contact-me page with a contact form who’s action is a PHP script that fires off an email via Mandrill. That all works fine.
When the call to Mandrill in the PHP script succeeds, I want to send the user back to the contact-me page with the GET method carrying the result variable - success in this example. So http://www.mysite.com/contact-me?result=sucess. And I think that is working too.
Here’s the problem, when I get back to the contact-me page I want to look for the result variable and not render the contact form, but instead render a success message. You guys have seen this many times on the web.
But with Grav and Twig, how do I get at that $_GET variable so I can find the contents of results?
AJAX is a possibility. But I’m not that good with it, nothing else on the site uses it (yet), and I’m thinking there should be a simple way to get there with HTML and Twig. Maybe not?
Grav is intentionally kept light-weight, it does not contain a full framework under the covers as these add overhead and would slow things down. There is some basic access to parts of the request in the URI object. Anything else you should add with a plugin. You can definitely do what your asking with a plugin because we have already done similar in the admin plugin.
Digging in here it looks as if I want to have my plugin listen for the onTwigSiteVariables event to set Twig variables for what I collect from $_GET in the plugin. Since $_GET is a super global, I assume my plugin will have access to it in the normal course of PHP?
I plan to create an array of what’s in $_GET and send that array to Twig as getArray.
Grav sends the $twig_vars array to Twig in twig.php in the processSite function. Do I have access in my plugin to that variable so that I can add my new variables to it to be passed to Twig?