I'm trying to submit my form using formspree in a static site I'm building with React. I've gotten close, but now completely lost.
I'm trying to use ES6 Promise function but don't know how to complete it.
Here is my current code:
import React from 'react';
import { Link } from 'react-router';
import { prefixLink } from 'gatsby-helpers';
import { config } from 'config';
import Headroom from 'react-headroom';
import Nav from './nav.js';
import '../css/main.scss';
import Modal from 'boron/DropModal';
import {Input, Label,Textarea, Button} from 're-bulma';
const modalStyle = {
minHeight: '500px',
backgroundColor: '#303841'
};
const backdropStyle = {
backgroundColor: '#F6C90E'
};
const contentStyle = {
backgroundColor: '#303841',
padding: '3rem'
};
const gotcha = {
display: 'none'
};
const email = 'https://formspree.io/dillonraphael@gmail.com';
export default class RootTemplate extends React.Component {
static propTypes = {
location: React.PropTypes.object.isRequired,
children: React.PropTypes.object.isRequired,
}
static contextTypes = {
router: React.PropTypes.object.isRequired,
}
constructor() {
super();
this.showModal = this.showModal.bind(this);
}
showModal () {
this.refs.modal.show();
}
formSubmit(e) {
e.preventDefault();
let data = {
name: this.refs.name.value,
email: this.refs.email.value,
message: this.refs.message.value
}
return new Promise((resolve, reject) => {
const req = new XMLHttpRequest();
req.open('POST', email);
});
console.log(data);
}
render() {
return (
<div>
<Headroom>
<Nav showModal={this.showModal}/>
</Headroom>
<Modal ref="modal" modalStyle={modalStyle} contentStyle={contentStyle} backdropStyle={backdropStyle}>
<form ref='contact_form' onSubmit={::this.formSubmit}>
<Label>Name:</Label>
<Input ref="name" />
<Label>Email:</Label>
<Input ref="email" type="email"/>
<Label>Message:</Label>
<Textarea ref="message" />
<Input type="text" name="_gotcha" style={gotcha}/>
<Button buttonStyle="isOutlined" color="isWarning">Submit</Button>
</form>
</Modal>
{this.props.children}
</div>
);
}
}
I also currently get this error:
Object {name: undefined, email: undefined, message: undefined}
Any help would be greatly appreciated. Really trying to learn.