Skip to content

Cleaner forms submit logic#1399

Open
Raruto wants to merge 1 commit intoagentejo:nextfrom
Raruto:forms-submit
Open

Cleaner forms submit logic#1399
Raruto wants to merge 1 commit intoagentejo:nextfrom
Raruto:forms-submit

Conversation

@Raruto
Copy link
Contributor

@Raruto Raruto commented Jan 22, 2021

Reorganization of the code within the Forms::submit function to allow finer extensibility by other developers.

All changes are backward compatible.


List of changes:

  • added 'forms.submit.email' event to allow finer filtering of sent emails (eg. to avoid creating a specific template for each newly created form):
// Filter email content

$this->app->trigger('forms.submit.email', [$form, &$data, $frm, &$body, &$options]);
  • added &$response parameter to 'forms.submit.after event to allow finer filtering of returned data (I don't really like phpmailer errors being sent directly to the browser)
// Filter submission response

$this->app->trigger('forms.submit.after', [$form, &$data, $frm, &$response]);
  • replace $this->app->renderer->file with $this->app->view (to allow access to app viewvars in email templates)
// Load custom email template

if ($template = $this->app->path("#config:forms/emails/{$form}.php")) {
    $body = $this->app->view($template, ['data' => $data, 'frm' => $frm]);
}
  • added a default modules/Forms/views/api/email.php template (also useful for help people understand how to create their owns)

Side notes

I just discovered the existence of this method PHPMailer::validateAddress($address, $patternselect), maybe this section could be further simplified?

$emails = array_map('trim', explode(',', $frm['email_forward']));
$filtered_emails = [];
foreach ($emails as $to){
// Validate each email address individually, push if valid
if ($this->app->helper('utils')->isEmail($to)){
$filtered_emails[] = $to;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant