Hi All thanks for reading this!
I have created a handle submit function that works on a login form. I want the form to not be able to be submit depending on the state of the inputs e.g email,password, password confirm.
Below displays a brief attempt I have had but this does not seem to work correctly.(I know the bottom two are now commented out but they did not work regardless.)
Using this logic what would be the best way to implment it ?
Below is my code in question.
handleSubmit(e) {
e.preventDefault();
try {
if (
!this.state.email < 8 //&&
//!this.state.password < 8
// this.state.password !== this.state.passwordConfirm
) {
alert(`please enter the form correctly `);
} else {
const data = { email: this.state.email, password: this.state.password };
fetch("/admin-Add-Users", {
method: "POST", // or 'PUT'
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
console.log("Success:", data);
})
.catch(error => {
console.error("Error:", error);
});
alert(`Congradulations you have signed up`);
}
} catch (e) {
console.log(e);
}
}
Aucun commentaire:
Enregistrer un commentaire