Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

402
Vistas
How to create a form with text and file input in react and send form data to server using Nodejs?

I am trying to send the form data with text and file inputs. By using multer i am able to only fetch file not the text data. Here is the form

import React from 'react'
const Addplayer=()=>{  
        return(
        <>
            <h1>Add player here</h1>
            <form method='POST' enctype='multipart/form-data'>
            <label>Enter the team name
                <input type="text" name='tn' placeholder='Team name'/>
                </label>
                <br></br><br></br><br></br>
                <label>Enter the player name
                <input type="text" name='pn' placeholder='Player name'/>
                </label>
                <br></br><br></br><br></br>
                <label>Enter the player age
                <input type="number" name='pa' placeholder='Player age'/>
                </label>
                
                <button type="submit">Submit</button>
            </form>


        </>
        
    )
}

I am using the multer middleware to fetch the file but i text fields of these form are not able to accessed in request body.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

See this example from the Multer docs (it says req.body will hold the text fields, if there were any, so the other fields are in req.body):

const express = require('express')
const multer  = require('multer')
const upload = multer({ dest: 'uploads/' })

const app = express()

app.post('/profile', upload.single('avatar'), function (req, res, next) {
  // req.file is the `avatar` file
  // req.body will hold the text fields, if there were any
})

PS. This comment has got a point:

How is the form submitted to the server? I don't see an action in your form element.

An action attribute (docs) specifies the URL the data should be sent to. In this case, you should set your Express.js endpoint here.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda