Skip to content

Is it possible to use multiple forms in the same page? #59

Answered by smeijer
vasco3 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

Yes, that is certainly possible. So depending on your need, you could either modify the form action, so that the form on the page points to a different backend handler. Or maybe just the same handler, but with a query arg, like:

import { handle, json } from "next-runtime";
import { Form, useFormSubmit } from "next-runtime/form";

export const getServerSideProps = handle({
  async get() {
    return json({ some: "data" });
  },

  async post({ query, req: { body } }) {
    if (query.action === 'create') { ... }
    if (query.action === 'update') { ... }
  }
});

export default function Home() {
  return (
    <div>
      <Form method="post" action="?action=create">
        <button type="…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@vasco3
Comment options

Answer selected by vasco3
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants