Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
How do i resolve a 400 error when posting form data in React?

I have problem submitting a form data using axios. I dont know what i'm doing wrong.I keep get a 400 status from the console and from the browser network, the form can be seen under payload but on the preview tab...it reads "browser sent a req the server could not understand". Here is the code below...



const Form = () => {
 
const [details, setDetails] = useState({
    surname: "",
    phone_number: "",
    passport: null,

  });


const submitForm = async(e) => {
    e.preventDefault()
    completeFormStep();
   

    const formData = new FormData();
    formData.append("surname", details.surname)
    formData.append("passport", details.passport)
    formData.append("phone_number", details.phone_number)
   
   try {
    
      const response = await Axios({
        method: "post",
        url: "https://pshs3.herokuapp.com/sponsored",
        data: formData,
        headers: { 'content-type': 'multipart/form-data' },
      })
      console.log('data', response)
    } catch(error) {
      console.log(error)
    }
  }
 
  

  return (
   <div>
                     <input
                      
                      name="surname"
                      type="text"
                      placeholder="Enter Surname"
                      value={details.surname}
                      onChange={(e) =>
                        setDetails({ ...details, surname: e.target.value })
                      }
                    />
                <input
                      type="text"
                      name="phone_number"
                      placeholder="Enter your phone number"
                      value={details.phone_number}
                      onChange={(e) =>
                        setDetails({ ...details, phone_number: e.target.value })
                      }
                    />
                    <input
                      
                      label="Upload Passport Photograph"
                      name="passport"
                      type="file"
                      accept="image/*"
                     
                      onChange={(e) =>
                        setDetails({ ...details, passport: e.target.files})
                      }
                    />
 
</div>
};

export default Form;



```I 
i've removed a greater part of the input fields for brevity. please I would appreciate any help to resolve the error(Failed to load resource: the server responded with a status of 400 (BAD REQUEST)). 
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!