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

4.7 KiB

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

--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.

Vai avanti, e assegna a ogni elemento inviabile un attributo name univoco di tua scelta. Eccetto i due input 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>
  <head>
    <title>Registration Form</title>
      <link rel="stylesheet" type="text/css" href="styles.css" />
  </head>
  <body>
    <h1>Registration Form</h1>
    <p>Please fill out this form with the required information</p>
    <form action='https://register-demo.freecodecamp.org'>
--fcc-editable-region--
      <fieldset>
        <label>Enter Your First Name: <input type="text" required /></label>
        <label>Enter Your Last Name: <input type="text" required /></label>
        <label>Enter Your Email: <input type="email" required /></label>
        <label>Create a New Password: <input type="password" pattern="[a-z0-5]{8,}" required /></label>
      </fieldset>
      <fieldset>
        <label><input type="radio" name="account-type" /> Personal Account</label>
        <label><input type="radio" name="account-type" /> Business Account</label>
        <label>
          <input type="checkbox" required /> I accept the <a href="https://www.freecodecamp.org/news/terms-of-service/">terms and conditions</a>
              </label>
      </fieldset>
      <fieldset>
        <label>Upload a profile picture: <input type="file" /></label>
        <label>Input your age (years): <input type="number" min="13" max="120" />
              </label>
        <label>How did you hear about us?
          <select>
            <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>Provide a bio:
                  <textarea 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;
}