The QuickEmail runs but not the FormIt. My error logs are not showing my anything, I cleared my all my cache, FormIt will in an empty template but not via a snippet.
FormIt’s job is to process user input from a submitted form on the screen. Since there’s no form, nothing has been submitted, so I’m not sure it can be used with runSnippet().
It’s possible that if you put the appropriate data into the $_POST array and then called FormIt with runSnippet() FormIt might process that data as a submitted form, though I’m not sure why you would want to do that, since it would be much simpler to just send the email with QuickEmail or call PhpMailer or the equivalent in your code.
If you want user input for FormIt to respond to, you’ll have to create a form to gather that and put it on the page. In that case, you might as well put the FormIt tag on that page.
I know this is an ancient thread and you have probably long forgotten about this. But for reference and others coming across this thread, I thought I’d share some new insights.
Recently I’ve had to use Formit to send a user off-site then reprocess the data and send an email when the user is sent back to the site. I decided to use Formit Hooks with a twist.
To do this I added a new &successHooks parameter to the Formit snippet that holds the email hook. When the user is redirected back to the page, Formit fires a prehook which in turn recalls the previously submitted data & data returned from the 3rd party site, then assigns it to the $_POST array then calls the $modx->runSnippet();. This works great, however, you must remember to unset the $_POST array i.e. $_POST = [] otherwise the main Formit snippet will rePost the form.
// This is an example of the preHook
// Set properties
$scriptProperties = $hook->formit->config;
// Reassign and unset
unset($scriptProperties['successHooks']);
unset($scriptProperties['preHooks']);
unset($scriptProperties['submitVar']);
unset($scriptProperties['validate']);
// Reassign successHooks to Hooks param
$scriptProperties['hooks'] = $hook->formit->config['successHooks'];
$_POST = $_SESSION['formit']['values'];
// Now re-run formit with the post hooks
$modx->runSnippet('formit', $scriptProperties);
// Clear out the POST Array
$_POST = [];
I’ll add onto this, in case someone isn’t already in a FormIt context - backstory, I had to save a $_POST submission to FormItSaveForm. Using QuickApi, a $_POST is sent to an endpoint. The endpoint represents a snippet that processes everything, but when I runSnippet FormIt, the $_POST wasn’t consumed like it should’ve been.
Since runSnippet wasn’t working, I tried by just loading the class like in the FormIt snippet:
Interesting. What does your endpoint look like? Is it in /assets/components/mypackage/endpoint.php or a snippet that is called from a Modx resource i.e. /endpoint/ → [[!myEndpointSnippet]]?
The extra I’m using, QuickApi does have a resource with a snippet on it.
Then it uses a plugin to reroute requests that go to your specified base route, default is api, to that resource. The snippet then loads the QuickApi class where it does the rest of its magic:star2:.