aboutsummaryrefslogtreecommitdiff
path: root/src/components/contact/Form.js
blob: ec398fa3d0745ba864541e537d198508f65c56c2 (plain) (blame)
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
import React, { Component } from 'react';

const encode = (data) => {
    return Object.keys(data)
        .map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key]))
        .join("&");
}

export default class Form extends Component {
    constructor(props) {
        super(props);
        this.state = { name: '', method: '', message: '' };
    }

    handleSubmit = e => {
        fetch('/', {
            method: 'POST',
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
            body: encode({ 'form-name': 'contact-form', ...this.state })
        });
        
        e.preventDefault();
    }
    
    handleChange = e => this.setState({ [e.target.name]: e.target.value });

    render() {
        const { name, method, message } = this.state;
        return(
            <div className="container-fluid">
                <div className="row">
                    <div className="col-lg-8">
                        <form name="contact-form" id="contact-form" action="/contact" onSubmit={this.handleSubmit} netlify>
                            <ul>
                                <li className="wow fadeInUp" data-wow-delay="1.4s">
                                    <label htmlFor="name">Name:</label>
                                    <div className="textarea">
                                        <input type="text" name="name" id="name" defaultValue={name} onChange={this.handleChange} required />
                                    </div>
                                </li>
                                <li className="wow fadeInUp" data-wow-delay="1.6s">
                                    <label htmlFor="method">Email/ Discord:</label>
                                    <div className="textarea">
                                        <input type="text" name="method" id="method" defaultValue={method} onChange={this.handleChange} required />
                                    </div>
                                </li>
                                <li className="wow fadeInUp" data-wow-delay="1.6s">
                                    <label htmlFor="message">Message:</label>
                                    <div className="textarea">
                                        <input type="text" name="message" id="message" defaultValue={message} onChange={this.handleChange} required />
                                    </div>
                                </li>
                            </ul>
                            
                            <button type="submit" name="contact-form" id="contact-form" className="send wow fadeInUp">
                                Send Message
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        )
    }
}