Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to overwrite fields after the form is submitted, but before actions are taken. #419

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears with your change, the form will only be processed IF it has a:

process:
  process: true
  ...

This would mean that all existing forms would no longer automatically process the fields.. Granted we currently only support the fillWithCurrentDateTime task, but still, it would not work until the form blueprint was updated.

break;

case 'captcha':

$captcha_config = $this->config->get('plugins.form.recaptcha');
Expand Down Expand Up @@ -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));
}
}
}

Expand Down