Quiz
- I would like to talk more about finding the form using a selector.
Sure. It's not really different from our other operations of finding things, as we did with buttons and such:
Then, in JS, we do:
Here, we have a form element:
So the JS part is like this:
The latter code is hidden inside our generic form handler.
- I'm still a little confused about what the callback function actually does.
Good question. Let's expand the previous code:
So the callback does the custom stuff for this form. In this case, it uses the Truck's
createOrdermethod. - Could you explain callback functions in more detail? Can a
callback be any function we define, and how does it relate to
addSubmitHandler?
Yes, it can be anything we want. It's how we hook into that form submission, so that we can do some custom processing.
- For forms that take files as a user input, are there any practices important for a front-end vs backend developers to know, use, or avoid to ensure the safety/privacy of the user's documents (in this case focusing specifically handling the files before they're stored on a server, as I imagine data storage broadly has a lot of other associated concerns)?
Wow, are you taking CS 304 instead? Great question, but outside the scope of CS 204. I'll say a few things here, but please follow up by email or in office hours if you'd like to learn more.
To upload files, we have to (1) use a different encoding type (
enctype) of form, and (2) a different input (type=file) which creates a file selection widget in the browser. The user can then select the file to upload, so hopefully, they don't compromise their own security. Once the file is uploaded, the back end needs to make sure things are stored securely on the server. - No particular questions at this time.
Great!