diff --git a/package-lock.json b/package-lock.json index d358b66..8af99fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5651,7 +5651,7 @@ }, "core-js": { "version": "2.5.5", - "resolved": "http://registry.npmjs.org/core-js/-/core-js-2.5.5.tgz", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.5.tgz", "integrity": "sha1-sU3ek2xkDAV5prUMq8wTLdYSfjs=" }, "firebase": { diff --git a/src/components/ContactForm.js b/src/components/ContactForm.js new file mode 100644 index 0000000..7882ce2 --- /dev/null +++ b/src/components/ContactForm.js @@ -0,0 +1,57 @@ +import React, { Component } from 'react'; + +const encode = (data) => { + return Object.keys(data) + .map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key])) + .join("&"); +} + +class ContactForm extends Component { + constructor(props) { + super(props); + this.state = { name: "", email: "", message: "" }; + } + + + handleSubmit = e => { + fetch("/", { + method: "POST", + headers: { "Content-Type": "application/x-www-form-urlencoded" }, + body: encode({ "form-name": "contact", ...this.state }) + }) + .then(() => alert("Success!")) + .catch(error => alert(error)); + + e.preventDefault(); + }; + + handleChange = e => this.setState({ [e.target.name]: e.target.value }); + + render() { + const { name, email, message } = this.state; + return ( +
+

+ +

+

+ +

+

+