Form actions on +layout.server.js
?
#6764
-
From what I can tell it's not possible to export actions from The use case I'm trying to address: global slideovers for things like newsletter subscription and enquiry forms, which are all part of our global layout. The easy workaround is to chuck these in something like |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
Just realised this is very likely because how would you call any action from a layout on anything but |
Beta Was this translation helpful? Give feedback.
-
It's because it couldn't fall back to native behavior - a layout is not a page you can reload. The way to solve this is to have a route which deals with the newsletter, and call actions from there in your layout. That way with JS enabled you stay on the current page, but if for some reason JS isn't enabled it redirects to the newsletter signup page instead. |
Beta Was this translation helpful? Give feedback.
-
I'm currently running into an issue with this. The above answer helped somewhat, except now I can't get the validations from the page. I have a I was able to get it working on a single route by using Is there a way to get the |
Beta Was this translation helpful? Give feedback.
-
Now you should be able to just put the load function in +layout.server.ts and the actions in +page.server.ts, that works fine for me! |
Beta Was this translation helpful? Give feedback.
It's because it couldn't fall back to native behavior - a layout is not a page you can reload. The way to solve this is to have a route which deals with the newsletter, and call actions from there in your layout. That way with JS enabled you stay on the current page, but if for some reason JS isn't enabled it redirects to the newsletter signup page instead.