I am currently stuck on a problem with Gravity Forms and ReactJS. I am trying to load a Gravity Form as a Modal in a ReactJS component for contact purposes. Basically, how I am currently set up is by doing a GET
from the WP-API
for the page with the form loaded in, and then using dangerouslySetInnerHTML
to build the page in the component. The problem is though that when I try to submit the form, its giving me a problem with the POST
. Its trying to submit it to the URL
from the GET
. I can use some serious help here on what would be the best approach.
import React, { PropTypes } from 'react';
import Modal from 'react-modal';
import $ from 'jquery';
class RequestContactModal extends React.Component {
constructor(props) {
super(props);
this.state = {
content: ''
};
}
componentWillMount() {
const wpApiUrl = '../wp-json/wp/v2/pages/61';
$.ajax({
url: wpApiUrl,
type: 'GET'
})
.done((response) => {
console.log(response);
this.setState({
content: response.content.rendered
});
})
.fail((response) => {
console.log('fail');
console.log(response);
});
}
handleSubmit = (ev) => {
ev.preventDefault();
this.props.closeModal();
}
handleCloseClick = (ev) => {
ev.preventDefault();
this.props.closeModal();
}
render() {
const customStyles = {
overlay: {
backgroundColor: 'rgba(0, 0, 0, 0.65)'
},
content: {
top: '50%',
left: '50%',
right: 'auto',
bottom: 'auto',
marginRight: '-50%',
transform: 'translate(-50%, -50%)',
background: '#fff'
}
};
return (
<Modal
isOpen={this.props.isOpen}
onRequestClose={this.props.closeModal}
style={customStyles}
>
<div>
<p>Gravity Forms</p>
<div dangerouslySetInnerHTML={{__html: this.state.content}} />
</div>
</Modal>
);
}
}
RequestContactModal.propTypes = {
closeModal: PropTypes.func.isRequired,
isOpen: PropTypes.bool
};
RequestContactModal.defaultProps = {
isOpen: false
};
export default RequestContactModal;