Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove submit button alert bug also add validation for phone number and clear the input fields on form submission #70

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/components/ContactUs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ const ContactUs = () => {
const [email, setEmail] = useState("")
const [message, setMessage] = useState("")
const [name, setName] = useState("")
const [number, setNumber] = useState("")

const handleSubmit = (e) => {
e.preventDefault()
if(!name.trim() || !message.trim() || !email.trim()){
if(!name.trim() || !message.trim() || !email.trim() || !number.trim()){
alert("Fill all the fields")
}
alert("Message sent successfully")
else if(name.trim() || message.trim() || email.trim() || number.trim()){
alert("Message sent successfully")
setName("")
setMessage("")
setEmail("")
setNumber("")
}
}


Expand Down Expand Up @@ -58,7 +65,9 @@ const ContactUs = () => {
<input required={true} type="email" value={email} onChange={(e)=> {
setEmail(e.target.value)
}} className="rounded-xl h-10 w-72 p-3" placeholder="Email: eg- [email protected]"/>
<input required={true} type="number" className="rounded-xl h-10 w-72 p-3" placeholder="Phone no.: eg- 65654-56554"/>
<input required={true} type="number" value={number} onChange={(e)=> {
setNumber(e.target.value)
}} className="rounded-xl h-10 w-72 p-3" placeholder="Phone no.: eg- 65654-56554"/>
<textarea required={true} value={message} onChange={(e)=> {
setMessage(e.target.value)
}} rows="3" cols="4" className="rounded-xl w-72 p-3" placeholder="Message: eg- Dear admin , I am intersted in your website. I want to collaborate..."/>
Expand Down