Skip to content

How to use multiple forms on a single page? #1569

Closed Answered by hollandThomas
dcastil asked this question in Q&A
Discussion options

You must be logged in to vote

It gets a bit verbose but here's how you can do it:

import type { ActionFunction } from 'remix';
import { Form, json, useTransition } from 'remix';

enum FormNames {
  FIRST_NAME_FORM = 'firstNameForm',
  LAST_NAME_FORM = 'lastNameForm',
}

export const action: ActionFunction = async ({ request }) => {
  await new Promise((res) => setTimeout(res, 1000));

  const formData = await request.formData();

  const formName = formData.get('formName');

  switch (formName) {
    case FormNames.FIRST_NAME_FORM:
      console.log('handle firstName form server side');
      return json({ firstName: formData.get('firstName') });

    case FormNames.LAST_NAME_FORM:
      console.log('handle lastName f…

Replies: 6 comments 2 replies

Comment options

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

Answer selected by machour
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
8 participants