GithubHelp home page GithubHelp logo

Comments (6)

mattcarrollcode avatar mattcarrollcode commented on December 8, 2023

Standard HTML forms provide the name and value of the button that submitted the form even if the button is outside the form tag:

from react.

SiddiqAM1 avatar SiddiqAM1 commented on December 8, 2023

import React, { useRef } from "react";

const Component = () => {
const submitButtonRef = useRef(null);

function action(formData) {

function handleSubmit(event) {

return (



export default Component;

from react.

SiddiqAM1 avatar SiddiqAM1 commented on December 8, 2023

Use a hidden submit button inside of the form tag and programmatically click it when the external button is clicked.

from react.

SiddiqAM1 avatar SiddiqAM1 commented on December 8, 2023

you can also use React Hook Form Library

from react.

mattcarrollcode avatar mattcarrollcode commented on December 8, 2023

This also seems to be a problem when using formAction on a button inside the form. If you have a button that has the formAction attribute the name and value of that button are not surfaced in the form data reguardless of whether the button is inside the form or outside the form.

Code example comparing a "default" submit button (which does surface the button's form data properly) and a button with the formAction attribute set with a client action handler:

from react.

sophiebits avatar sophiebits commented on December 8, 2023

Code pointer for debugging – it's meant to be added here:

if (submitter) {
// The submitter's value should be included in the FormData.
// It should be in the document order in the form.
// Since the FormData constructor invokes the formdata event it also
// needs to be available before that happens so after construction it's too
// late. We use a temporary fake node for the duration of this event.
// TODO: FormData takes a second argument that it's the submitter but this
// is fairly new so not all browsers support it yet. Switch to that technique
// when available.
const temp = submitter.ownerDocument.createElement('input'); =;
temp.value = submitter.value;
(submitter.parentNode: any).insertBefore(temp, submitter);
formData = new FormData(form);
(temp.parentNode: any).removeChild(temp);

from react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.