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

Form plugin sends email before data got validated and written #10544

Open
cbratschi opened this issue Jan 13, 2025 · 2 comments
Open

Form plugin sends email before data got validated and written #10544

cbratschi opened this issue Jan 13, 2025 · 2 comments
Labels
status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@cbratschi
Copy link

Describe the Bug

The confirmation email is sent in the beforeChange hook:

In case validation fails no data got stored.

Solution: use afterChange hook or the afterCommit hook I proposed in another ticket.

Link to the code that reproduces this issue

https://github.com/cbratschi/payload

Reproduction Steps

See above.

Which area(s) are affected? (Select all that apply)

plugin: form-builder

Environment Info

Binaries:
  Node: 22.12.0
  npm: 10.9.0
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  payload: 3.13.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:23 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6031
  Available memory (MB): 65536
  Available CPU cores: 16
@cbratschi cbratschi added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Jan 13, 2025
@akhrarovsaid
Copy link
Contributor

Hey @cbratschi,

So, the collection beforeChange hook is supposed to run only after validation succeeds in a manner where you can be confident that the data is valid and will be saved to the document. In other words, "before changes" are saved. The docs even point out that it will run within create and update operations.

Moving this to an afterChange should still work, although I don't think it's necessary here personally.

@cbratschi
Copy link
Author

@akhrarovsaid I received the email, then validation failed and no document was saved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

2 participants