I want to load JSON data from a cookie in the from so it could send via mail. But I cannot get it working. So I tried the demo from the documentation „loadCustomValues“. But this also didn‘t work. All I see in the email are the placeholders.
Here my FormIt call:
[[!FormIt?
&preHooks=Cookie2FormIt
&hooks=email
&emailTpl=fi_email_taxi
&emailTo=dsfgasdf@dsfgdsf.com
]]
Here my email template:
Gast: [[+guest]]
Zimmernummer: [[+room]]
Here my preHook Snippet:
<?php
$hook->setValues(array(
'room' => '11',
'guest' => 'mustermann',
));
return true;
For setting email placeholders, use a hook and not a preHook.
1 Like
But as I read the documentation correct I need to set it in the preHook to become available in the email hook: https://docs.modx.com/3.x/en/extras/formit/formit.hooks
Note that using the setValues() method here will make the corresponding placeholders available to your email chunk; the effect of manually setting values is similar to adding hidden fields to your form.
This sentence from the documentation is wrong.
When you set a value with $hook->setValue()
in a preHook, this only works on the first request, when the form it not submitted.
On form submission, the values you set here get ignored
So for a value to be available as a placeholder in the email hook, either use $hook->setValue()
in a custom hook that runs before the email hook, or maybe you could use $modx->setPlaceholder('key','value')
in the prehook.
Seams your right. I added it as a hook and it works.