Closed counselorbot[bot] closed 2 years ago
Move on to the next issue.
Go ahead and merge this branch to main
to move on. Great work finishing this section!
⚠️ If you receive a
Conflicts
error, simply pressResolve conflicts
and you should be good to merge!
Week 4 Step 2 ⬤⬤◯◯◯◯◯ | 🕐 Estimated completion: 20-25 minutes
Error Handling ~ Sir this is a Wendy's
Demo: 🐰
Ideally, users will fill the web form with the correct information. However, people make mistakes. In this step, we will be implementing some form validation to make sure that a user has inputted text value before submitting their password.
✅ Task:
bunnimage-frontend
branchmultipart/form-data
inindex.html
index.html
that acceptsimage/x-png,image/jpeg
and add the attributename=image
index.js
to create an alert if either the file input or thename
input is nulltype
attribute to"submit"
bunnimage/index.html
andbunnimage/script.js
bunnimage
ontomain
, and only merge the pull request when the bot approves your changes!🚧 Test your Work
Open up your LiveServer plugin and start your server.
‼️ You have three test cases to try
1. **The "correct" way**: Submit both a file and text. Check that you receive "Thanks!" 2. **The "unexpected" way (file)**: Submit a file that is not png or jpeg. Does it work? 3. **The "unexpected" way (text input)**: Try submitting without entering a username. You should get an alert box that says "No name error."1: Accepting Images as an Input
In HTML Forms, the
enctype
attribute specifies how the form-data should be encoded when submitting it to the server. Like we learned before, if we want to upload files, we need send form-data encoded asmultipart/form-data
To add the image upload input, add an additional file input within the form & change the submit button's
type
.2: Input Validation?
We need to validate two things.
❓ How do you check that the image is either .png or .jpeg format
The HTML `` accept Attribute specifies a filter for what file types the user can pick from the file input dialog box. The accept attribute can only be used with . ```html❓ How do you check that the text box isn't empty
To validate that the name isn't null, check if `document.getElementById("username").value` isn't empty, to change the `output` div to "Thanks!", or display an `alert("No name error.")` > :bulb: **Hint**: Use your JavaScript conditional skills!📹 Walkthrough Video