-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact_form.jsx
139 lines (128 loc) · 3.75 KB
/
contact_form.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React from 'react';
import $ from 'jquery';
class ContactForm extends React.Component {
constructor(props) {
super(props);
this.state = {
name: "",
email: "",
designation: "",
company: "",
address: "",
message: "",
}
this.handleName = this.handleName.bind(this);
this.handleEmail = this.handleEmail.bind(this);
this.handleDesignation = this.handleDesignation.bind(this);
this.handleCompany = this.handleCompany.bind(this);
this.handleAddress= this.handleAddress.bind(this);
this.handleMessage = this.handleMessage.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
};
handleName(e) {
this.setState({
name: e.target.value
})
}
handleEmail(e) {
this.setState({
email: e.target.value
})
}
handleDesignation(e) {
this.setState({
designation: e.target.value
})
}
handleCompany(e) {
this.setState({
company: e.target.value
})
}
handleAddress(e) {
this.setState({
address: e.target.value
})
}
handleMessage(e) {
this.setState({
message: e.target.value
})
}
handleSubmit(e) {
e.preventDefault();
$.ajax({
url: '/api/messages',
type: 'POST',
cache: false,
data: {message: {body: "body", email: this.state.email, name: this.state.name}},
});
if (this.state.name === "" || this.state.email === "" || this.state.designation === "" || this.state.company === "" || this.state.address === "" || this.state.message === "") {
return
} else {
// $.ajax({
// url: "/api/messages",
// method: "POST",
// data: {message: {body: "body", email: this.state.email, name: this.state.name}},
// })
// setTimeout(() => {
// this.setState({
// name: "",
// email: "",
// designation: "",
// company: "",
// address: "",
// message: "",
// })}, 1)
}
}
render() {
// let email = `mailto:[email protected]?subject=Information Request&body=${body}`;
// let body = `Name: ${this.state.name}%0D%0A%0D%0AEmail: ${this.state.email}%0D%0A%0D%0ADesignation: ${this.state.designation}%0D%0A%0D%0ACompany: ${this.state.company}%0D%0A%0D%0AAddress: ${this.state.address}%0D%0A%0D%0A${this.state.message}`
return (
<form className="contact-form" >
<h1>Contact Form</h1>
<input
className="contact-input"
type="text"
placeholder="Name"
value={this.state.name}
onChange={this.handleName}/>
<input
className="contact-input"
type="text"
placeholder="Email"
value={this.state.email}
onChange={this.handleEmail}/>
<input
className="contact-input"
type="text"
placeholder="Designation"
value={this.state.designation}
onChange={this.handleDesignation}/>
<input
className="contact-input"
type="text"
placeholder="Company"
value={this.state.company}
onChange={this.handleCompany}/>
<input
className="contact-input"
type="text"
placeholder="Full address (City, State/Province, Country)"
value={this.state.address}
onChange={this.handleAddress}/>
<textarea
className="contact-input"
id="message-box"
type="textarea"
placeholder="Message"
value={this.state.message}
onChange={this.handleMessage}/>
<button className="submit-button" onClick={this.handleSubmit}>Submit</button>
</form>
)
};
};
export default ContactForm;
// <a className="submit-button" onClick={this.handleSubmit} href={email}>Submit</a>