|
| 1 | +import React from "react"; |
| 2 | +import { Link } from "react-router-dom"; |
| 3 | +import Button from "../../common/Button"; |
| 4 | +import axios from "axios"; |
| 5 | +const AJAX_ROOT = process.env.AJAX_ROOT; |
| 6 | + |
| 7 | +const HomeContactUs = props => { |
| 8 | + const sendResponse = event => { |
| 9 | + event.preventDefault(); |
| 10 | + let formElement = document.getElementById("contact-us-form"); |
| 11 | + let formData = new FormData(formElement); |
| 12 | + axios({ |
| 13 | + method: "post", |
| 14 | + url: `${process.env.AJAX_ROOT}/api/web/contact/`, |
| 15 | + data: formData |
| 16 | + }).then(response => { |
| 17 | + if (response.status === 201) { |
| 18 | + formElement.reset(); |
| 19 | + document.getElementById("cv-home-form-success").innerHTML = |
| 20 | + response.data.message; |
| 21 | + } |
| 22 | + }); |
| 23 | + }; |
| 24 | + const CONTACT_US_TITLE = "Contact Us"; |
| 25 | + return ( |
| 26 | + <div className="cv-home-contact-us cv-container" id="contact-us"> |
| 27 | + <h1 className="cv-home-showcase-heading"> |
| 28 | + {CONTACT_US_TITLE} |
| 29 | + </h1> |
| 30 | + <form |
| 31 | + className="cv-home-contact-form" |
| 32 | + encType="multipart/form-data" |
| 33 | + action="http://example.com/cgiscript.pl" |
| 34 | + method="post" |
| 35 | + id="contact-us-form" |
| 36 | + onSubmit={sendResponse} |
| 37 | + > |
| 38 | + <section className="cv-home-contact-form-elements"> |
| 39 | + <input |
| 40 | + className="cv-input-text" |
| 41 | + type="text" |
| 42 | + name="name" |
| 43 | + placeholder="Name" |
| 44 | + required |
| 45 | + /> |
| 46 | + <br /> |
| 47 | + <input |
| 48 | + className="cv-input-text" |
| 49 | + type="email" |
| 50 | + name="email" |
| 51 | + placeholder="Email" |
| 52 | + required |
| 53 | + /> |
| 54 | + <br /> |
| 55 | + <input |
| 56 | + className="cv-input-text" |
| 57 | + type="text" |
| 58 | + name="message" |
| 59 | + placeholder="Message/Query" |
| 60 | + required |
| 61 | + /> |
| 62 | + <br /> |
| 63 | + <label className="cv-input-label" htmlFor="image"> |
| 64 | + Any screenshot/image you would like to add : |
| 65 | + </label> |
| 66 | + <input className="cv-input-file" type="file" name="image" /> |
| 67 | + </section> |
| 68 | + <input |
| 69 | + className="cv-button cv-button-dark" |
| 70 | + type="submit" |
| 71 | + name="submit" |
| 72 | + value="Submit" |
| 73 | + /> |
| 74 | + <br /> |
| 75 | + <span className="cv-home-form-success" id="cv-home-form-success" /> |
| 76 | + </form> |
| 77 | + </div> |
| 78 | + ); |
| 79 | +}; |
| 80 | + |
| 81 | +export default HomeContactUs; |
0 commit comments