Can someone review my code for a contact form?
Answered
English Angora posted this in #help-forum
English AngoraOP
I'm kinda new to interfacing with APIs and doing form validation. I'm unsure if I did the best practices with fetching. My form validations are very lengthy. The code for the webpage is here:
https://github.com/M-Valentino/M-Valentino_NextJS/blob/main/src/pages/contact.jsx
The code for the validations are here:
https://github.com/M-Valentino/M-Valentino_NextJS/blob/main/src/utils/validations.js
The code for the API to handle submissions:
https://github.com/M-Valentino/M-Valentino_NextJS/blob/main/src/pages/api/sendMessage.js
https://github.com/M-Valentino/M-Valentino_NextJS/blob/main/src/pages/contact.jsx
The code for the validations are here:
https://github.com/M-Valentino/M-Valentino_NextJS/blob/main/src/utils/validations.js
The code for the API to handle submissions:
https://github.com/M-Valentino/M-Valentino_NextJS/blob/main/src/pages/api/sendMessage.js
Answered by B33fb0n3
for me it's working fine. Some things that I would change:
1. show a success message and hide the input fields (so replace with the success message). That gives a better UX
2. whitespaces are special characters, yes, but if I enter a ENTER in my message, I can't send it. So either remove them or let them through
3. validate the email. I saw you done that a little bit, but it's possible to enter none existing emails. You can use a regex, to validate the email address also for the TLD
@English Angora
1. show a success message and hide the input fields (so replace with the success message). That gives a better UX
2. whitespaces are special characters, yes, but if I enter a ENTER in my message, I can't send it. So either remove them or let them through
3. validate the email. I saw you done that a little bit, but it's possible to enter none existing emails. You can use a regex, to validate the email address also for the TLD
@English Angora
7 Replies
English AngoraOP
Oh, here is the actual webpage for the form: https://mark-valentino.vercel.app/contact
for me it's working fine. Some things that I would change:
1. show a success message and hide the input fields (so replace with the success message). That gives a better UX
2. whitespaces are special characters, yes, but if I enter a ENTER in my message, I can't send it. So either remove them or let them through
3. validate the email. I saw you done that a little bit, but it's possible to enter none existing emails. You can use a regex, to validate the email address also for the TLD
@English Angora
1. show a success message and hide the input fields (so replace with the success message). That gives a better UX
2. whitespaces are special characters, yes, but if I enter a ENTER in my message, I can't send it. So either remove them or let them through
3. validate the email. I saw you done that a little bit, but it's possible to enter none existing emails. You can use a regex, to validate the email address also for the TLD
@English Angora
Answer
English AngoraOP
Thanks @B33fb0n3 . I gotta figure out how to accept enters. maybe I just need to add \n to the regex
@B33fb0n3 for me it's working fine. Some things that I would change:
1. show a success message and hide the input fields (so replace with the success message). That gives a better UX
2. whitespaces are special characters, yes, but if I enter a *ENTER* in my message, I can't send it. So either remove them or let them through
3. validate the email. I saw you done that a little bit, but it's possible to enter none existing emails. You can use a regex, to validate the email address also for the TLD
<@266358318123974663>
English AngoraOP
I'm actually not seeing your message in the database 😬
English AngoraOP
So the database updates on localhost but not on the deployment. Why?
Since I already marked this as a solution but I still need help I'm making another help post @B33fb0n3