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

120
Views
how to send only one value of mail to backend if there are multiple inputs to axios post

Here I have 3 inputs of mail, if an user wants to fill any 1 input with his input , then only that particular input which will be filled by the user should be sent to the backend. pls help!:)

const App =() => {
  const [email,setEmail]=useState("");
  const [emailEA,setEmailEA]=useState("");
  const [emailFoo,setEmailFoo]=useState("");

  const submitEmail={
    Axios.post("http://localhost:3001/",{email,emailEA,emailFoo})
  }
  return (
    <div className="App">
      <Navbar/>
      <Banner/>
      <input 
        className="email"
        value={email} 
        onChange={(e)=>{
            setEmail(e.target.value)
        }}
        placeholder="Your email address"
      />  
      <TailorMadeServices/>
      <WhyUs/>
      <Testimonial/>
      <Hearit/>
      <EarlyAcc/>
      <input 
        value={emailEA}
        placeholder="Your Email Address"  
        onChange={(e)=>{
          setEmailEA(e.target.value)
        }}
        className="eainput1"
      />
      <Footer/>
      <input 
        className="fmail"
        placeholder="Your Email Address"
        value={emailFoo}
        onChange={(e)=>
          {
          setEmailFoo(e.target.value)
        }
      }
        />
    </div>
  );
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use this code in submitEmail function.

// test values
const email = 'email@test.com'
const emailFoo = ''
const emailEA = 'emailEA@test.com'

const emails_to_send = {email, emailFoo  ,emailEA}
for(const email in emails_to_send){
  if(!emails_to_send[email].match(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/g)) delete emails_to_send[email]
}
//     Axios.post("http://localhost:3001/",emails_to_send)
console.log(emails_to_send)

Note: Uncomment the axios.post line while using this code.

Note: Although the code works properly , I think that sending unfilled emails to backend shouldn't be a problem.

about 4 years ago · Juan Pablo Isaza Report
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!