Skip to content

Instantly share code, notes, and snippets.

@Musharofchy
Created May 22, 2023 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Musharofchy/d07d8d6b2a3108f77be4951e8a33f165 to your computer and use it in GitHub Desktop.
Save Musharofchy/d07d8d6b2a3108f77be4951e8a33f165 to your computer and use it in GitHub Desktop.
import axios from "axios";
import React, { useState } from "react";
export default function Forms() {
// Input Change Handling
const [inputs, setInputs] = useState({
email: "",
subject: "",
message: "",
});
const handleOnChange = (event) => {
event.persist();
setInputs((prev) => ({
...prev,
[event.target.id]: event.target.value,
}));
};
// Server State Handling
const handleOnSubmit = (event) => {
event.preventDefault();
axios({
method: "POST",
url: "https://formbold.com/s/{form_id}",
data: inputs,
})
.then((r) => {
console.log("hello");
})
.catch((r) => {
console.log("error");
});
};
return (
<form onSubmit={handleOnSubmit}>
<input
onChange={handleOnChange}
value={inputs.email}
id="email"
type="email"
name="email"
placeholder="Email"
/>
<input
onChange={handleOnChange}
value={inputs.subject}
id="subject"
type="text"
name="subject"
placeholder="Subject"
/>
<textarea
onChange={handleOnChange}
value={inputs.message}
id="message"
name="message"
placeholder="Type your message"
/>
<button type="submit"> Send Message </button>
</form>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment