Challenge: Movie Search
HTML inputs are cool, but it would be cooler if the data actually went somewhere when the user clicked the "Submit" button. Learn about HTML forms to create an interactive, user-driven movie search on a webpage!
Note: For the "Submit" button to work in HyTop, the project must be opened in a separate window.
Background
Web developers use HTML forms to send data from their webpages to servers. For more information about the flow of data from forms, read this article: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data
Instructions
For this challenge, you will create a webpage with a form. When a user submits the form, the browser will go to the IMDb Advanced Title Search page, using the data from the form to filter the results. Before starting to build the HTML page, play around with the IMDb search here: https://www.imdb.com/search/title
Notice that when you submit the form, the redirected URL reflects the data they entered. It uses query string parameters to communicate with the server. The form populates those values, and the server parses them and returns the proper results. The webpage you create in this challenge will simulate the IMDb form, but you can personalize it however you like!
Setup
- Create a new HTML page, and add the basic tags:
html, andbody - Add a header at the top of your page with the text "Movie Search"
The form basics
- Add a
formelement under the header - Set the
actionattribute of the form to point to https://www.imdb.com/search/title - Inside the form, create a new
pelement - Inside the new
pelement, create a "Submit" button- To do this, create an
inputelement, and set itstypeattribute tosubmit
- To do this, create an
- Open your file in a web browser, and verify that clicking "Submit" will navigate to the IMDb page
Adding basic inputs
Add a "Title" input where the user can enter for a title they wish to search. Additionally, add in a "Now Playing" checkbox, so the user can choose to search only for titles which are currently in theaters.
- Inside the form, above the "Submit" button, create a
h3element that says "Title" - Under the "Title"
h3, add aninputelement - On the
input, set thetypeattribute totext, and thenameattribute to "title"- The
nameattribute determines the field on the IMDb search
- The
- Create another
h3element that says "Now Playing" - Under the "Now Playing"
h3, add a checkboxinput(set thetypeattribute tocheckbox) - On the checkbox input, set the
nameattribute to "now_playing" - On the checkbox input, set the
valueattribute to "restrict"- This way, when the checkbox is checked, it will set "now_playing=restrict"
- Open your file in a web browser, and verify that searching for some titles works properly
Adding a "Genres" dropdown
Add a dropdown with a few genres, so the user can further narrow down their search if they so choose.
- Inside the form, add another
h3element saying "Genre" - On the next line, create a
selectelement - Set the
nameattribute of theselectto "genres" - Within the
selectelement, add anoptionelement that contains the text "All" - Set the
valueattribute of theoptionelement to blank ("")- This will mean that no genre is set in the search
- Create three additional
optionelements within theselectelement - For each
optionelement, the text andvalueattribute should match, and should be real genres - Open your file in a web browser, and verify that searching for some genres works properly
Adding a "Rating" radio button set
Add some radio buttons so the user can narrow down their search by rating.
- Inside the form, add another
h3element that says "Rating" - On the next line, add a
pelement- This
pelement will be one radio button option
- This
- Inside the radio
pelement, create aninputelement withtype"radio" - Set the
nameattribute of the radioinputto "certificates"- Giving radio buttons the same
namevalue will ensure that only one in the group is checked
- Giving radio buttons the same
- Set the
valueattribute of the radioinputto "US:G" - Outside of the
input, but within the radiopelement, insert the text "G" - Repeat the above steps and create radio
pelements for "US:PG" and "US:PG-13"- Make sure all the
nameattributes are "certificates", and they contain text
- Make sure all the
- Open your file in a web browser, and verify that searching for some ratings works properly
Adding other fields
Once you have added the fields above, revisit the IMDb Advanced Title Search page. Take a look at some of the options on that form, and how they data is represented in the query string of the URL after you submit the form. Try to add some other inputs to your webpage, or you can even try to statically set some filter values using hidden inputs!
More input types
Next Steps
After completing the Movie Search Challenge, move on to the Post Challenge.