Fixed the form.

This commit is contained in:
Batuhan Berk Başoğlu 2021-04-03 22:31:39 -04:00
parent 54b371fa06
commit a06cfe552f
2 changed files with 17 additions and 17 deletions

View file

@ -166,11 +166,8 @@ class ContactUs extends Component {
this.form.validateFields(); this.form.validateFields();
if (!this.form.isValid()) { if (!this.form.isValid()) {
console.log('form is invalid: do not submit'); return;
} else { } else {
console.log('form is valid: submit');
}
axios({ axios({
method: "POST", method: "POST",
url: "http://localhost:3002/send", url: "http://localhost:3002/send",
@ -178,15 +175,18 @@ class ContactUs extends Component {
}).then((response) => { }).then((response) => {
if (response.data.status === 'success') { if (response.data.status === 'success') {
alert("Message Sent."); alert("Message Sent.");
this.resetForm() this.resetForm();
} else if (response.data.status === 'fail') { } else if (response.data.status === 'fail') {
alert("Message failed to send.") alert("Message failed to send.");
} }
}) })
} }
}
resetForm() { resetForm() {
this.setState({ firstname: '', lastname: '', email: '', message: '' }) this.setState({ firstname: '', lastname: '', email: '', message: '', agent: '', house: '' })
} }
} }

View file

@ -27,10 +27,10 @@ router.post('/send', (req, res, next) => {
var firstname = req.body.firstname var firstname = req.body.firstname
var lastname = req.body.lastname var lastname = req.body.lastname
var email = req.body.email var email = req.body.email
var message = req.body.message
var agent = req.body.agent var agent = req.body.agent
var house = req.body.house var house = req.body.house
var content = `firstname: ${firstname} \n lastname: ${lastname} \n email: ${email} \n message: ${message} \n agent: ${agent} \n house: ${house}` var message = req.body.message
var content = `First Name: ${firstname} \n Last Name: ${lastname} \n E-mail: ${email} \n Agent: ${agent} \n House: ${house} \n Message: ${message} `
var mail = { var mail = {
from: email, from: email,