Groove Guitars: Tables and Forms (Lab 7)

This is Lab 7 in Developing Web Pages (BUS1880) and Web Fundamentals (CSCI1450). Do not start this lab until you have completed the Module 7 slideshow.

The objective of this lab is two-fold: 1) to practice building and styling an HTML table, and 2) to build a contact form connected to a real PHP script so you can see it actually submit data.

This lab assumes that you have a website template you can use as a starting point. I require students in my class to make a template, so they don’t have to start from scratch every time they make a new website. If you need a template, you can make one: Making a Website Template.

In this lab, you’ll build the home page for Groove Guitars, a fictional guitar shop. You’ll create an HTML table showing the store’s open hours, and a contact form wired up with a PHP script so you can see it working. There are three pages to the Groove Guitars website:

  1. Home Page (index.html) which is covered in this lab on Tables and Forms (Lab 7).
  2. About Page (about.html) which is covered in the Multimedia lab (Lab 8).
  3. Grooves Page (grooves.html) which is covered in the Multimedia lab (Lab 8).

Once you complete this lab plus the Multimedia lab you will have a complete website for your portfolio.

You’ll build the home page in three sections. In Section A, you’ll set up your files and build the header, navigation, and hero image. In Section B, you’ll add the Hours of Operation table. In Section C, you’ll create the contact form and connect it to a working PHP script. Work through the sections in order, since each one picks up where the last one left off.

When finished, your home page will look something like the image below, but with your fonts and colors:

Completed Groove Guitars home page example with logo, hero image, hours of operation table, and contact form

Please note:

Images: If you choose to find and use images other than the ones I provided, be sure that they are royalty-free. You may want to publish this website as an example of your work, so it is important to choose images you have the right to use. Do not use images you find on a Google search.

Use of AI: For my students in CSCI1450 and BUS1880, you may not use AI for the coding any assignment for this course. However, you may use AI to create an alternative logo, which would give you more design flexibility.

Jump to:

Jump to:

Section A. Header, Nav and Hero Image

Before you start coding, you need to get organized. This section has step-by-step instructions to help you get a good start on your web page.

Step 1. Copy Template HTML and CSS

Open Mac Finder or Windows File Explorer. Copy (or duplicate) your entire templates folder inside of your websites folder. Name the new folder “groove-guitars”. The index.html will be the home page for your portfolio website. Make sure it is named index.html and not template.html. Remove any extra files in the groove-guitars folder.

File organization showing the groove-guitars folder with index.html and style.css inside the websites folder

Step 2. Website Metadata (in the <head>)

In index.html, change the <title> to “Groove Guitars :: Home” and change the description to:

Groove Guitars carries the grooviest guitars on the planet! Stop by our store to find your groove.

Your <head> should look like the example below:

Completed head section with meta charset, viewport, description, title, and stylesheet link

Save the file and refresh your browser tab to double-check the title and description for typos.

Step 3. Download Images and Add to “images” folder

Download the images for this website from the link below.

Download Groove Guitars Images

Create an images folder inside of the groove-guitars folder. Add the images to the folder.

File organization showing the images folder inside groove-guitars with the logo and photo files

If your file organization doesn’t look like the screenshot above, then go back to Mac Finder or Windows File Explorer and rearrange your files and folders so it matches.

Step 4. Install Logo

  • Add the logo to the website <header>. Remember that the code for an image looks like this: <img src="" height="" width="" alt="" class="">
    • The logo is in the images folder and is named groove-guitars-logo.png.
    • The width for the logo image is 570px.
    • The height for the logo image is 269px.
    • For the alt text, you could say something like: “Logo for Groove Guitars.” The key for the alt text is to provide text for the screen reader. So you could even say something more descriptive like: Groove Guitars logo with a guitar with a groovy flower print.
    • Name the class attribute “logo”.
  • Save and look at your logo. It’s a bit too large, right? Let’s add a max-width so that it isn’t quite so large on the web page.
  • Select the logo class in the CSS and add a max-width of 275px. In order to keep it at the right aspect ratio, we also need to set the height property to auto.
  • Center the logo. Because it is an image, you need to first change the logo display value to “block”. Then you can center the logo with margin-left: auto and margin-right: auto. (A shortcut is to simply put in “margin: 0 auto”.)
  • Add a bit of padding. I recommend 20px of padding.

With all of these changes, your code should look like the example below:

Header element with the Groove Guitars logo image tag

Notice that the <img> tag sits right inside the <header>, where the logo belongs.

CSS for the logo class with max-width, height, display, margin, and padding

With this CSS in place, your logo should be centered and capped at a reasonable size no matter how wide the screen is.

Step 5. Add Navigation

Your navigation will come from your template, so all you have to do is change the links and page names.

Update the navigation in index.html to include links to the following pages:

  • index.html for Home
  • about.html for the About page (Lab 8)
  • grooves.html for the Grooves page (Lab 8)

The about.html and grooves.html pages don’t exist yet. We will add the other two pages in the next lab, Multimedia (Lab 8).

Step 6. Add Hero and <h1>

For the hero image, we’ll use a full-width image.

HTML: Add the hero image <div> with a class of home-hero and the <h1> text. Place the <div> for the hero in-between the closing </nav> and opening <main>.

Hero div placed between the closing nav tag and the main tag with an h1 reading Find Your Groove

CSS: You will need two selectors to design the hero: .home-hero, and .home-hero h1.

  • .home-hero Selector: Use the image named “guitars.jpg” in the images folder for the hero image. Set the background-size to cover. You also need to set a height.
  • .home-hero h1 Selector: For the h1 tag inside of the hero, you will have to at minimum turn off the default margin, so that the hero image touches the navigation bar.

Feel free to try different colors or designs. The only requirement is that it needs to look good and be full-width. This is how I made the sample:

CSS for the home-hero background image and the home-hero h1 text styling

Is your hero image not full width? Make sure you place the <div> for the hero between the closing </nav> and opening <main> tags. In our templates, we put a max-width on the <main> section, so if you put your hero in the <main> section then the max-width applies to it.

Step 7. Copy website text into the <main> section.

Cut and paste this text into the <main> section on the website. You’ll need to add markup, but copying this into the <main> section will save you some typing.

Welcome to Guitar Groove!

At Groove Guitars, we are more than just a guitar store; we are a haven for musicians and enthusiasts alike, where the art of crafting and playing guitars merges seamlessly with the rhythm of your life. Nestled in the heart of the city, our store is a haven for those who live and breathe music.

At Groove Guitars, we don't just sell guitars; we celebrate the beauty of music, craftsmanship, and the enduring power of melody. Whether you're a professional musician or a weekend strummer, our store is a place where you can find your rhythm, explore new horizons, and groove to the beat of your own tune. Visit us today and embark on a musical journey that will resonate with you for a lifetime.

Hours of Operation

Stop by our store! The right guitar for you makes all the difference. We specialize in matching players to the right guitar. We can help you find your groove.

<!-- Insert table here -->

How Can We Help You?

Looking for a certain guitar? Let us know and we can help you look. Need help with guitar and bass lessons? Let us know your skill level and hours available and we will match you with an instructor.

<!-- Insert form here -->

Add <h2> tags to the headings and <p> tags to the paragraphs. The hours of operation will be a table, and we will work on that next. Do you see the two HTML comments? Those mark where you will place the HTML table and HTML form.

Section B. Add the Table

Step 1. Add the Table

Build the Hours of Operation table directly in index.html, starting where you see the <!-- Insert table here --> comment, using <table>, <tr>, <th>, and <td>. (Need a refresher on how those elements work? See Lesson 9.1: Website Tables.) Here’s the text for it, to save you some typing:

  • Start with an opening <table> tag and a closing </table> tag. Everything else goes between them.
  • The first row (Day, Hours, Services Available) is your header row. Start it with <tr>, but use <th> instead of <td> for each cell.
  • Each day after that gets its own row: a new <tr>, with a <td> for the day, a <td> for the hours, and a <td> for the services.
  • Don’t forget a closing tag for every tag you open, including </tr> after each row.
Day
Hours
Services Available

Sunday
11am to 3pm
Sales Only

Monday
11am to 9pm
Sales, Lessons, Repairs

Tuesday
11am to 9pm
Sales, Lessons, Repairs

Wednesday
11am to 9pm
Sales, Lessons, Repairs

Thursday
11am to 9pm
Sales, Lessons, Repairs

Friday
11am to 6pm
Sales, Lessons, Repairs

Saturday
11am to 6pm
Sales, Lessons, Repairs available until 3pm

Step 2. Style the Table

Once your table is in index.html, add some CSS in style.css to style it, above the media queries.

Now that we have a table, we need to design it with CSS:

  • Select td and th (td, th) and add a border to the table cells. Remember that a border requires three properties, and looks like this: border: 1px solid gray; Need help picking border styles? Try the Border Generator.
  • Select table and add: border-collapse: collapse;
  • Style the table header cells (th) and cells (td). Choose your own colors.
  • At your option, you may want to use an every-other-row color, by selecting tr:nth-child(even).
  • Want to center the table on the page? Select table and add margin: 0 auto;. (Need a refresher on centering elements? See How to Center Web Page Elements.)

Your table should look something like the image below, but with your own design:

Example Hours of Operation table with purple header row

Nice work, your table is complete!

Stop here, BUS1880 students! You’ve completed everything required for Lab 7. (CSCI1450 students, continue on to Section C below.)

Section C. Create a Form

Build a contact form directly in index.html, starting where you see the <!-- Insert form here --> comment, with fields for name, email, phone, and comments, plus a working submit button. (Need a refresher? See Lesson 9.2: HTML Forms, Lesson 9.3: Special Form Fields, and Lesson 9.4: Styling HTML Forms with CSS.)

Step 1. Add the <form> Tag and Attributes

Add a <form> tag to index.html, below the table, with the action and method attributes:

<form action="https://webdevstudents.com/portfolio/submit-form.php" method="post">

</form>

Don’t forget the closing </form> tag. Everything else in the form goes between the opening and closing tags.

Curious what the action attribute points to? Take a look at the script.

Step 2. Add the Name Fields and Submit Button

First Name: Here is the field to get you started:

<label for="first_name">*First Name</label>
<input type="text" name="first_name" id="first_name" required><br><br>

Notice the asterisk (*) at the start of the label text. That’s just a plain character you’re typing, a visual cue to the user that the field is required. It doesn’t do anything on its own: the required attribute on the <input> tag is what actually enforces it.

Last Name: Copy the First Name field to add a Last Name field. Change the for, name, and id attributes to last_name.

Submit Button: Add a submit button with the type attribute set to submit. To change the words on the button, use the value attribute, for example value="Let's Rock".

Check your code against the screenshot below.

Screenshot of code to start a simple form with a first name, last name, and submit button.

Open index.html in your browser and check that your form matches the screenshot below:

Simple form showing only first name, last name and a submit button.

Now fill out your form and hit the submit button. If your action attribute is set up correctly, you should see a Congratulations screen like the one below, along with the First and Last Name you entered:

After testing the form, at this stage the only the First Name and Last Name fields come through on the PHP script.

If you don’t see the Congratulations screen at all, check your <form> attributes. The Congratulations screen also tells you whether each field is working: if a field’s data doesn’t come through, you’ll see a note like “The Email field is not coming through the form” instead of what you typed. If you see that message for a field, check two things:

  • Is the name attribute set correctly? That’s what sends the data to the script.
  • Is the field actually between the opening <form> and closing </form> tags? A field placed outside the form won’t be submitted at all.

Step 3. Add Email and Phone Fields

Email: Copy the First Name field again and paste it under Last Name. Use “*Email” as the label text, and set the for, name, and id attributes to email. Set the type to email. This tells the browser to check that a properly formatted email address was entered before the form can be submitted.

Cell: Copy the field once more and paste it under Email. Use “Cell” as the label text, with no asterisk, since this field won’t be required. Set the for, name, and id attributes to phone, and set the type to tel. This doesn’t force a specific format, since phone numbers vary too much to validate simply, but on phones it brings up a numeric keypad instead of a full keyboard, making the number easier to enter. Remove the required attribute.

Fill out and submit your form again to confirm the new fields work. If a field’s data doesn’t carry over to the Congratulations screen, double check its name attribute.

Step 4. Style the Input Fields

  • Add a light gray background color to the text, email, and tel fields (#eeeeee).
  • Add a dark red background color with white text to the submit button. Feel free to use your own colors instead, and try adjusting the border color or border-radius too.
CSS showing how to color the form fields using the targeted input types.

Refresh your browser to see the new colors appear in your form fields and submit button.

Step 5. Fix the Form Layout

Now it’s time to clean up the form layout.

  • Remove the <br> tags. We’ll use padding and margin in the CSS instead.
  • Select label in the CSS. Float it to the left, set the width to 8em, and set padding-right to 1em.
  • Select input in the CSS. Give it 1em of margin-bottom, and set display to block.
  • Select the submit button specifically with input[type=submit] and set display to block.
  • Want to center the form on the page? Give your form selector a max-width (such as 400px) and set margin: 0 auto;. (Need a refresher on centering elements? See How to Center Web Page Elements.)
Form screenshot after CSS added to improve the layout of the form fields.

Compare your layout to the screenshot. Your labels should sit neatly to the left of each field.

Step 6. Add a Comments Field

Comments: Add a <textarea> field for comments. Place it above your submit button:

<label for="comments">*How can we help you?</label>
<textarea id="comments" name="comments" required></textarea>

Submit your form again to make sure the comments field works.

The CSS for the comments field won’t quite match the others yet. Add textarea to the same CSS selector list as input, so the same styles apply to both. You can also give it the same background color.

CSS to style a textarea field consistent with the other fields in the lab.

With that change, your comments field should pick up the same background color as the fields above it.

Screenshot of the lab form with all fields including the field. The textarea label is How can we help you?

Now test the whole form one more time. Fill out every field, first name, last name, email, cell, and comments, and submit it. Check the Congratulations screen carefully and confirm each field shows the value you typed. If anything is missing, go back and check that field’s name attribute and make sure it sits between the <form> and </form> tags.

That’s it for Guitar Grooves for now! You’ve built a working home page with a logo, hero image, hours table, and a contact form that actually submits. Next up is the Multimedia lab (Lab 8), where you’ll add the About page with a store map, and the Grooves page with embedded music and video, rounding out the Groove Guitars website.

Checklist for Grading

Here is a checklist of what I will be looking for when grading the website:

All students:

CSCI1450 students only (BUS1880 students can stop after the table):


Now you know how to build a table and a working contact form! Move on to Lab 8 to add multimedia like a map, video, and audio to your Groove Guitars website.

Screenshot of the website we are making in the lab.

Need Help?

Using AI for coding is not allowed in this course, so if you get stuck simply Make an Appointment for office hours. In addition, if you run into a bug as you are working, you may email your websites folder to me at susan.metoxen@saintpaul.edu.

Browse All Lessons

CSS Design Tools