diff --git a/form.php b/form.php index 792fb471..e07af12e 100644 --- a/form.php +++ b/form.php @@ -384,9 +384,11 @@ public function onFormProcessed(Event $event) $action = $event['action']; $params = $event['params']; - $this->process($form); - switch ($action) { + case 'process': + $this->process($form); + break; + case 'captcha': $captcha_config = $this->config->get('plugins.form.recaptcha'); @@ -857,6 +859,14 @@ protected function process($form) if (!empty($field['process']['fillWithCurrentDateTime'])) { $form->setData($field['name'], gmdate('D, d M Y H:i:s', time())); } + if (!empty($field['process']['twig'])) { + $twig = $this->grav['twig']; + $vars = [ + 'form' => $form + ]; + // Process with Twig + $form->setData($field['name'], $twig->processString($field['process']['twig'], $vars)); + } } }