Form data not submitting to external API
See original GitHub issueI’m passing next js form parameters to an external API written in Laravel which send a simple email, the API working fine when I send a post request using postman but , when I submit below Next Js form to the API nothing happen, no call make to API please help me
import React, {Component} from 'react'
import fetch from 'isomorphic-unfetch'
class Contact extends Component {
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this)
}
handleSubmit = async () => {
var email = this.refs.email.value.trim();
var message = this.refs.message.value.trim();
const res = await fetch('http://iotdash.dev/contact', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: JSON.stringify({
'email': email,
'message': message
})
});
const data = await res.json();
};
render () {
return (
<div className="row contact-wrapper container-width center-align">
<h3>Contact Us</h3>
<p className="gray-text">Leave us some information and we will be in touch as soon as possible!</p>
<form onSubmit={this.handleSubmit}>
<div className="col m6 form-field left-align">
<label className="gray-text">
First Name *
</label>
<input className="gray-text" ref="first_name" required type="text"/>
</div>
<div className="col m6 form-field left-align">
<label className="gray-text">
Last Name *
</label>
<input className="gray-text" ref="last_name" required type="text"/>
</div>
<div className="col m6 form-field left-align">
<label className="gray-text">
Email *
</label>
<input className="gray-text validate" ref="email" required type="email"/>
</div>
<div className="col m6 form-field left-align">
<label className="gray-text">
Phone Number
</label>
<input className="gray-text" ref="phone" type="text"/>
</div>
<div className="col m12 form-field left-align">
<label className="gray-text">
Message *
</label>
<textarea className="gray-text" ref="message" required/>
</div>
<div className="col m12 left-align contact-button-wrapper">
<input className="button button-yellow submit-button" type="submit" value="Contact Us" />
</div>
</form>
</div>
)
}
}
export default Contact
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
AJAX How to submit different form data to external API
You can submit whatever data you want regardless of number of forms using Ajax. Below Ajax does the same var formData = "name=ravi&age=31"; ......
Read more >Sending form data - Learn web development | MDN
This article looks at what happens when a user submits a form — where does the data go, and how do we handle...
Read more >Submit Contact Form 7 Field Data to External API or Email
In this video, learn how to pick submitted data from Contact Form 7 and email it or send it to an external API...
Read more >POST Form Data With JavaScript Fetch API - YouTube
Use JavaScript to collect & submit form data... Professional JavaScript Course: https://bytegrad.com/professional-javascript?n=697 ...
Read more >Send form data to external applications - Progress Community
Are there any resources discussing how I can send form data to an external application that is not Marketo, Oracle or Insight?
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Found it 😄 The default event was not prevented, which causes a page refresh.
Great 👍