Skip to content

Bug: missing button data in form when submitted via formAction #27391

@mattcarrollcode

Description

@mattcarrollcode

When a form action is triggered by a button that is outside the form's tag the button's name and value is missing from the form data provided to the action. When the button submitting the form is inside the form tag the button's form data is properly surfaced to the action:

output

React version: 0.0.0-experimental-2807d781a-20230918

Steps To Reproduce

  1. Create a form that calls an action when submitted with a button outside the form tag submits the form. The button that submits the form should have the name and value attributes set with non-null values. The action should take a formData argument and log the button's value:
    function Component() {
      function action(formData) {
        console.log(formData.get("n1"));
      }
      return (
        <>
          <button type="submit" name="n1" value="v1" form="form-id">
            Submit
          </button>
          <form action={action} id="form-id"></form>
        </>
      );
    }
    
  2. Click the button that submits the form

Link to code example: https://codesandbox.io/s/flamboyant-meadow-gcvpx9?file=/App.js

The current behavior

The formData provided to the form action doesn't contain the key-value pair information of the button that submitted the form when the button is outside the form's tag. This means that nothing is logged because the n1 key doesn't exist in formData

The expected behavior

The value of the external button to be logged (v1 in the example above) because formData includes the

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