# Validation part in Survey form

**URL:** <https://forum.freecodecamp.org/t/validation-part-in-survey-form/415547>\
**Category:** General\
**Created:** [August 16, 2020, 2:48am UTC](https://forum.freecodecamp.org/t/validation-part-in-survey-form/415547 "2020-08-16T02:48:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajgorakshay](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/rajgorakshay/32/134407_2.png) [@rajgorakshay](https://forum.freecodecamp.org/u/rajgorakshay)\
**Post date:** [August 16, 2020, 2:48am UTC](https://forum.freecodecamp.org/t/validation-part-in-survey-form/415547/1 "2020-08-16T02:48:12Z")

</div>

So that I lost my earlier version of Survey form project due to browser unable to connect and followed by page refresh - [Codepen.io](http://Codepen.io) I have re-started and am stuck with validation part. Of course; I have text/ email/ numbers to validate and I am stuck @Roma with the name validation part.

Found some meaningful code on Youtube but still unable to encash on it due to the original classes in use…and I can’t muck around anymore - enough number of hours wasted and work is lost so…if someone can please guide?

```auto
.input-container {
  margin-bottom: 15px;
  max-width: 300px;
}
.input {
  display: block;
  width: 100%;
  padding: 12px;
}

.input-container[data-error].input {
  border-color: #c292432;
  background: #fffafa;
}

.input-container[data-error]::after {
  content= attr(data-error);
}

```

My code so far:

> **[Fork Me! FCC: Test Suite Template](https://codepen.io/freeCodeCamp/pen/MJjpwO)**
>
> ...

---

<div class="post-metadata">

**Author:** ![Vumbhoni](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/vumbhoni/32/174017_2.png) [@Vumbhoni](https://forum.freecodecamp.org/u/Vumbhoni)\
**Post date:** [August 16, 2020, 5:48am UTC](https://forum.freecodecamp.org/t/validation-part-in-survey-form/415547/2 "2020-08-16T05:48:27Z")

</div>

albeit I can’t see your code, the only validation required for the name is that it is a REQUIRED input. So give your name INPUT tag an attribute of REQUIRED.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [August 16, 2020, 9:20am UTC](https://forum.freecodecamp.org/t/validation-part-in-survey-form/415547/3 "2020-08-16T09:20:07Z")

</div>

you have given the freeCodeCamp pen

please save your work and share the link to your own pen with your work

---

<div class="post-metadata">

**Author:** ![rajgorakshay](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/rajgorakshay/32/134407_2.png) [@rajgorakshay](https://forum.freecodecamp.org/u/rajgorakshay)\
**Post date:** [August 16, 2020, 10:01am UTC](https://forum.freecodecamp.org/t/validation-part-in-survey-form/415547/4 "2020-08-16T10:01:51Z")

</div>

@Vumbhoni I checked my code; and it appears I’ve mentioned required=required as the attribute to Name/ Email/ Number etc input fields…  
My bad; please find my code URL:

> **[Fork Me! FCC: Test Suite Template](https://codepen.io/rajgorakshay/pen/eYZZPGa)**
>
> ...

I’d like to try and make use of the below logic I came across when validating Name field:

```auto
.input-container {
  margin-bottom: 15px;
  max-width: 300px;
}
.input {
  display: block;
  width: 100%;
  padding: 12px;
}

.input-container[data-error].input {
  border-color: #c292432;
  background: #fffafa;
}

.input-container[data-error]::after {
  content= attr(data-error);
}

```

---

<div class="post-metadata">

**Author:** ![Vumbhoni](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/vumbhoni/32/174017_2.png) [@Vumbhoni](https://forum.freecodecamp.org/u/Vumbhoni)\
**Post date:** [August 16, 2020, 10:30am UTC](https://forum.freecodecamp.org/t/validation-part-in-survey-form/415547/5 "2020-08-16T10:30:56Z")

</div>

Hi @rajgorakshay,

The issue is that you have given your LABEL tag an ID value of “name”, and your NAME INPUT tag an ID value of “name-label”. The same is true for your email tags.

To link a LABEL to an INPUT, use the FOR attribute on your LABEL and assign it the name the value of the name of the input you want to link it to.

Also, REQUIRED attribute is a boolean. You only need to specify it, not specify and assign.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [August 16, 2020, 3:07pm UTC](https://forum.freecodecamp.org/t/validation-part-in-survey-form/415547/6 "2020-08-16T15:07:26Z")

</div>

look below the failed user story to see the error:  
for example below failed user story " 4. Inside the form element, I am required to enter my name in a field with id=“name”. If I do not enter a name I will see an HTML5 validation error." there is written:

> `input field with id="name" should be a text field`

the #name id is given to a label element, so it can’t be a text input. Please, give the #name id to the appropriate element

---

<div class="post-metadata">

**Author:** ![Vumbhoni](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/vumbhoni/32/174017_2.png) [@Vumbhoni](https://forum.freecodecamp.org/u/Vumbhoni)\
**Post date:** [August 16, 2020, 5:16pm UTC](https://forum.freecodecamp.org/t/validation-part-in-survey-form/415547/7 "2020-08-16T17:16:13Z")

</div>

Hi @ILM

User story 4, says you should have an input element on the form where you are required to input your name, give this input an id value of name.  
User story 10 says you should have a label for your name-input element, give your label an ID value of “name-label”.

try this

```auto
  <label for="name" id="name-label">Name:</label>
  <input type="text" name="name" id="name" required placeholder="Enter your name" />

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [August 16, 2020, 5:21pm UTC](https://forum.freecodecamp.org/t/validation-part-in-survey-form/415547/8 "2020-08-16T17:21:26Z")

</div>

thank you for your answer, but I know how to solve that. I wasn’t answering to you

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:43pm UTC](https://forum.freecodecamp.org/t/validation-part-in-survey-form/415547/9 "2021-06-01T18:43:25Z")

</div>

Closed on June 1, 2021, 6:43pm UTC


