formSubmit

This commit is contained in:
Kar
2023-05-04 13:51:40 +05:30
parent 0dd4c47f37
commit 52e0800ce7
3 changed files with 75 additions and 46 deletions

36
src/pages/test/2.jsx Normal file
View File

@@ -0,0 +1,36 @@
export default function PageWithJSbasedForm() {
const handleSubmit = async (event) => {
event.preventDefault()
const data = {
"status":"published",
name: event.target.schoolName.value,
country: event.target.country.value,
}
const JSONdata = JSON.stringify(data)
const endpoint = 'https://management.beanstalkedu.com/items/school'
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSONdata,
}
const response = await fetch(endpoint, options)
const result = await response.json()
alert(`Is this your full name: ${result.data}`)
}
return (
<form onSubmit={handleSubmit}>
<label >School Name</label>
<input type="text" name="schoolName" required />
<label htmlFor="last">Country</label>
<input type="text" id="last" name="country" required />
<button type="submit">Submit</button>
</form>
)
}