question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allow form actions without page component

See original GitHub issue

Describe the problem

I would like to make form actions available from anywhere in the app, as described in the documentation:

<form method="POST" action="/login">
  <!-- content -->
</form>

This does however require me to make a route /login, /logout, /register, … while it would make sense to me to group them in one file exporting several actions such that I can do (as in the example from the docs):

<form method="POST" action="/login?/register">

However, if I just make a file /login/+page.server.js without a +page.js I get the following error:

node.component is not a function TypeError: node.component is not a function

Describe the proposed solution

Allow to have a similar construct as Actions in a pure API endpoint (+server.js).

Alternatives considered

Workaround

This can be solved by adding an actual page and redirecting directly (I have no need for a login page in this case).

Importance

nice to have

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
dummdidummcommented, Oct 28, 2022

Ok I think I understand now - so it’s about not having to create login/+server.js, logout/+server.js etc files because you’d like to have these things closer together / not as many files lying around. What I don’t understand it the connection to your code example, you use that together with a form. So you want to use the <form method="POST" action=".."> feature but the action should point to a +server.js file?

0reactions
Rich-Harriscommented, Nov 17, 2022

Cool — will close this in that case

Read more comments on GitHub >

github_iconTop Results From Across the Web

form with no action and where enter does not reload page
A form without an action attribute is not a form, according to standards - and will actually cause a page reload in some...
Read more >
How to submit a form or a part of a form without a page refresh ...
In this article, we will learn how to submit a form or a part of a form without a page refresh using JQuery,...
Read more >
The Form element - HTML: HyperText Markup Language | MDN
The <form> HTML element represents a document section containing interactive controls ... Instead, use the accept attribute on <input type=file> elements.
Read more >
Submit a Form Without Page Refresh Using jQuery - Code
A great way to improve the user experience of your website is to validate and submit forms without a page refresh.
Read more >
Forms - React
This form has the default HTML form behavior of browsing to a new page when the user submits the form. If you want...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found