Skip to content

Add a way to intercept and change form action result in handle hook #9676

@qurafi

Description

@qurafi

Describe the problem

There's no native way to intercept form actions and changing its result before being rendered.

Why I need this
I'm experimenting automatic endpoint/form validation based on the defined schema file. I will load all needed schemas in the hook handle and validate them and return result back to user. Something similar to what's in Fastify framework

For standalone endpoints this works fine. but with form actions, this is challenging as I have to render the page with the error props but sveltekit yet doesn't provide any mechanism to change that.

Describe the proposed solution

We could either have a seperate hook function in hooks.server or provide a callback in resolve function similar to transformPageChunk

Alternatives considered

  1. Manually define the desired behavior in each form action with a shared function. but this is redundant
  2. A hacky way to use transformPageChunk to replace form in kit.start(app, __sveltekit_dev.element, { node_ids: [0, 2], data, form: null, error: null }); with the desired results. but this is a hacky solution and requires more testing and could break pages and introduce security issues.

Importance

would make my life easier

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions