freeCodeCamp/curriculum/challenges/english/01-responsive-web-design/basic-html-and-html5/create-a-form-element.engli...

2.5 KiB

id title challengeType videoUrl forumTopicId
bad87fee1348bd9aede08830 Create a Form Element 0 https://scrimba.com/p/pVMPUv/cmQ3Kfa 16817

Description

You can build web forms that actually submit data to a server using nothing more than pure HTML. You can do this by specifying an action on your form element. For example: <form action="/url-where-you-want-to-submit-form-data"></form>

Instructions

Nest your text field inside a form element, and add the action="/submit-cat-photo" attribute to the form element.

Tests

tests:
  - text: Nest your text input element within a <code>form</code> element.
    testString: assert($("form") && $("form").children("input") && $("form").children("input").length > 0);
  - text: Make sure your <code>form</code> has an <code>action</code> attribute which is set to <code>/submit-cat-photo</code>
    testString: assert($("form").attr("action") === "/submit-cat-photo");
  - text: Make sure your <code>form</code> element has well-formed open and close tags.
    testString: assert(code.match(/<\/form>/g) && code.match(/<form [^<]*>/g) && code.match(/<\/form>/g).length === code.match(/<form [^<]*>/g).length);

Challenge Seed

<h2>CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>

  <a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>

  <p>Things cats love:</p>
  <ul>
    <li>cat nip</li>
    <li>laser pointers</li>
    <li>lasagna</li>
  </ul>
  <p>Top 3 things cats hate:</p>
  <ol>
    <li>flea treatment</li>
    <li>thunder</li>
    <li>other cats</li>
  </ol>
  <input type="text" placeholder="cat photo URL">
</main>

Solution

<h2>CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>
  
  <a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
  
  <p>Things cats love:</p>
  <ul>
    <li>cat nip</li>
    <li>laser pointers</li>
    <li>lasagna</li>
  </ul>
  <p>Top 3 things cats hate:</p>
  <ol>
    <li>flea treatment</li>
    <li>thunder</li>
    <li>other cats</li>
  </ol>
  <form action="/submit-cat-photo">
    <input type="text" placeholder="cat photo URL">
  </form>
</main>