Skip to content

Mission-Ready/html-exercise02-html-form-CassJah

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

02 Exercise - HTML Forms

Brief

Build a Create an account form with various input types in HTML

form stacked


Rationale

Almost every web app will use forms in one incarnation or another, so HTML forms will be an important part of your skillset.


Getting Started

  1. git clone this repository into your main exercise folder.
  • If you are not too sure how to do it, please follow this video to see how to git clone the repository into your device.
  1. The code for this exercise should go into the /Submission folder.

Exercise Part A - Add Form Elements

  1. Create an index.html file in the Submission folder. Create the HTML base code by typing ! and pushing tab

  2. Add a heading inside the body: <h1>Create an account</h1> inside the <body> element.

  3. Create a <form></form> element after the <h1>

  4. Add an action and method attribute to your form, so it looks like the below snippet:

    <form action="mailto:[email protected]" method="post"></form>

    This will make your form submission be emailed to your instructor.

  5. Inside your <form> element, add the following HTML form elements, with the corresponding labels and input types.

    • Ensure each of your labels is linked to your input by using the for attribute, that matches the id of the form input

    • Ensure each of your inputs has the name attribute.

      <label for="name">Name</label> <input id="name" name="name" type="text" />
    Label Input name Input type Options
    Name name text n/a
    Email email email n/a
    Password password password n/a
    Address address textarea n/a
    Country country select New Zealand, Australia
    Sign up to newsletter? newsletter checkbox n/a
  6. Add a submit button before the closing </form> tag:

    <button type="submit">Create account</button>`
  7. Test your page in your web browser

    • Do your form inputs look correct? For example, does it hide the text when you type your password? Do your checkbox and select work correctly?

    • When you click the label, does it automatically highlight the form input?

      label highlight

  8. Fill in the form fields and submit the form. All things going well, you should get a success message. If you get an error message, try and fix the error.

  9. You will notice all the form elements are on the same line. This is because form elements are inline by default.

    inline form

    To make everything appear in its own line, wrap each label/input combination in a <div> element. For example:

    <div>
      <label for="name">Name</label>
      <input id="name" name="name" type="text" />
    </div>
  10. Ensure your HTML is valid using the W3C HTML Validator.

  11. Commit your code to git

Your form should look like the screenshot below. It's not well designed, but it's functional.

form stacked

Acceptance criteria

  • All form fields are present that are listed in the specification
  • When clicking a label, it focuses on the corresponding form input
  • When a user pushes enter while in a form element, the form submits
  • When the form submits, it displays the Formspree confirmation page
  • The form inputs have appropriate names, so when the form is submitted the correct data appears in the Formspree email

Exercise Part B - Make name and email required inputs

It's possible to make form inputs required, by using the required attribute. You can read more about The required attribute on MDN

  1. Make the Name and Email form inputs required, by adding the required attribute to the inputs.

    <input id="name" name="name" type="text" required />
  2. Commit your code to git

Acceptance criteria

  • If the name input is empty, the form can not be submitted
  • If the email input is empty, the form can not be submitted

Exercise Part C - Add a reset button

We can also have a button for reset all the input.

  1. Now try to create one reset button.

    <input type="reset" value="Reset" />
  2. Your button section should look like Alt text

Acceptance criteria

  • When you click Reset button, all the input field should become empty without any text inside.

Submit your Exercise

Walkthrough Solution Videos

About

html-exercise02-html-form-CassJah created by GitHub Classroom

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages