Skip to content

Instantly share code, notes, and snippets.

@lmas3009
Last active March 11, 2022 03:48
Show Gist options
  • Save lmas3009/895d01024710b46e3083fb9b6f5518f9 to your computer and use it in GitHub Desktop.
Save lmas3009/895d01024710b46e3083fb9b6f5518f9 to your computer and use it in GitHub Desktop.
A Simple MERN Full Stack Application
import React from 'react';
import axios from 'axios'
import { Link, browserHistory, IndexRoute, BrowserRouter as Router, Route, Switch } from 'react-router-dom';
function AddDetails() {
const handleSubmit = (e) => {
e.preventDefault();
var number = e.target.tel.value
if (number.length == 10) {
axios.post("https://user-details-mern.herokuapp.com/details")', {
Name: e.target.name.value,
FName: e.target.fname.value,
Address:e.target.address.value,
PhonNo:e.target.tel.value,
Email: e.target.email.value
})
.then(function (response) {
try {
window.location.href = "/"
} catch (error) {
console.log(error);
}
})
.catch(function (error) {
console.log(error);
});
}
else {
alert("Phone Should be correct")
}
}
return (
<Router browserHistory>
<div className="form">
<form onSubmit={handleSubmit}>
<label>Enter User Details</label>
<div className="Name">
<label>Name</label>
<input
type="text"
name="name"
placeholder="Enter your Name"
required
/>
</div>
<div className="FName">
<label>Full Name</label>
<input
type="text"
name="fname"
placeholder="Enter your Full Name"
required
/>
</div>
<div className="Address">
<label>Address</label>
<input
type="address"
name="address"
placeholder="Enter your Address"
required
/>
</div>
<div className="PhonNo">
<label>Phone Number</label>
<input
type="tel"
name="tel"
placeholder="Enter your Phone Number"
maxlength="10"
required
/>
</div>
<div className="Email">
<label>Email</label>
<input
type="email"
name="email"
placeholder="Enter your Email Id"
required
/>
</div>
<input type="submit" onClick="window.location.href=window.location.href" value="Submit" className="submit"/>
<Link to="/" className="link"><input onClick="window.location.href=window.location.href" type="button" className="btn" value="Go Back"/></Link>
</form>
</div>
</Router>
)
}
export default AddDetails;
@Shreyachaudhary1112
Copy link

i am getting an error in this file

@lmas3009
Copy link
Author

lmas3009 commented Mar 11, 2022

Like what error your are getting @Shreyachaudhary1112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment