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

Cleaner forms submit logic #1399

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open

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