freeCodeCamp/curriculum/challenges/italian/14-responsive-web-design-22/learn-html-forms-by-buildin.../60fad1cafcde010995e15306.md

5.1 KiB

id title challengeType dashedName
60fad1cafcde010995e15306 Step 41 0 step-41

--description--

Per quanto riguarda l'invio dei moduli, è utile oltre che una buona pratica, fornire ogni elemento inviabile di un attributo name. Questo attributo è utilizzato per identificare l'elemento una volta che il modulo è stato inviato.

Dai a ogni elemento inviabile un attributo name univoco di tua scelta, a eccezione dei due elementi radio.

--hints--

Dovresti assegnare all'input relativo al nome un attributo name. PS Io avrei scelto first-name

assert.isNotEmpty(document.querySelector('fieldset:nth-child(1) > label:nth-child(1) > input')?.name);

Dovresti assegnare all'input relativo al cognome un attributo name. PS Io avrei scelto last-name

assert.isNotEmpty(document.querySelector('fieldset:nth-child(1) > label:nth-child(2) > input')?.name);

Dovresti assegnare all'email un attributo name. PS Io avrei scelto email

assert.isNotEmpty(document.querySelector('input[type="email"]')?.name);

Dovresti assegnare alla password un attributo name. PS Io avrei scelto password

assert.isNotEmpty(document.querySelector('input[type="password"]')?.name);

Dovresti assegnare alla checkbox un attributo name. PS Io avrei scelto terms

assert.isNotEmpty(document.querySelector('input[type="checkbox"]')?.name);

Dovresti assegnare al file un attributo name. PS Io avrei scelto file

assert.isNotEmpty(document.querySelector('input[type="file"]')?.name);

Dovresti assegnare al number un attributo name. PS Io avrei scelto age

assert.isNotEmpty(document.querySelector('input[type="number"]')?.name);

Dovresti assegnare all'elemento select un attributo name. PS Io avrei scelto referrer

assert.isNotEmpty(document.querySelector('select')?.name);

Dovresti assegnare all'elemento textarea un attributo name. PS Io avrei scelto bio

assert.isNotEmpty(document.querySelector('textarea')?.name);

Non dovresti assegnare a nessun elemento option un attributo name.

[...document.querySelectorAll('option')]?.forEach(option => assert.isUndefined(option?.name));

Non dovresti assegnare a nessun elemento label un attributo name.

[...document.querySelectorAll('label')]?.forEach(label => assert.isUndefined(label?.name));

Non dovresti assegnare a nessun elemento fieldset un attributo name.

[...document.querySelectorAll('fieldset')]?.forEach(fieldset => assert.isEmpty(fieldset?.name));

--seed--

--seed-contents--

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Registration Form</title>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <h1>Registration Form</h1>
    <p>Please fill out this form with the required information</p>
    <form method="post" action='https://register-demo.freecodecamp.org'>
--fcc-editable-region--
        <fieldset>
        <label for="first-name">Enter Your First Name: <input id="first-name" name="first-name" type="text" required /></label>
        <label for="last-name">Enter Your Last Name: <input id="last-name" name="last-name" type="text" required /></label>
        <label for="email">Enter Your Email: <input id="email" name="email" type="email" required /></label>
        <label for="new-password">Create a New Password: <input id="new-password" name="new-password" type="password" pattern="[a-z0-5]{8,}" required /></label>
      </fieldset>
      <fieldset>
        <label for="personal-account"><input id="personal-account" type="radio" name="account-type" /> Personal Account</label>
        <label for="business-account"><input id="business-account" type="radio" name="account-type" /> Business Account</label>
        <label for="terms-and-conditions" name="terms-and-conditions">
          <input id="terms-and-conditions" type="checkbox" required name="terms-and-conditions" /> I accept the <a href="https://www.freecodecamp.org/news/terms-of-service/">terms and conditions</a>
        </label>
      </fieldset>
      <fieldset>
        <label for="profile-picture">Upload a profile picture: <input id="profile-picture" type="file"/></label>
        <label for="age">Input your age (years): <input id="age" type="number" min="13" max="120" /></label>
        <label for="referrer">How did you hear about us?
          <select id="referrer" name="referrer">
            <option value="">(select one)</option>
            <option value="1">freeCodeCamp News</option>
            <option value="2">freeCodeCamp YouTube Channel</option>
            <option value="3">freeCodeCamp Forum</option>
            <option value="4">Other</option>
          </select>
        </label>
        <label for="bio">Provide a bio:
          <textarea id ="bio" rows="3" cols="30" placeholder="I like coding on the beach..."></textarea>
        </label>
      </fieldset>
--fcc-editable-region--
      <input type="submit" value="Submit" />
    </form>
  </body>
</html>
body {
  width: 100%;
  height: 100vh;
  margin: 0;
  background-color: #1b1b32;
  color: #f5f6f7;
}

label {
  display: block;
  margin: 0.5rem 0;
}