# About form error, is it possible to add a certain class like 'invalid' on the input/select/raido itself?

**URL:** <https://discourse.laminas.dev/t/about-form-error-is-it-possible-to-add-a-certain-class-like-invalid-on-the-input-select-raido-itself/2483>\
**Category:** Components & MVC\
**Tags:** laminas-form\
**Created:** [September 2, 2021, 8:42am UTC](https://discourse.laminas.dev/t/about-form-error-is-it-possible-to-add-a-certain-class-like-invalid-on-the-input-select-raido-itself/2483 "2021-09-02T08:42:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jobsfan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/jobsfan/32/399_2.png) [@jobsfan](https://discourse.laminas.dev/u/jobsfan)\
**Post date:** [September 2, 2021, 8:42am UTC](https://discourse.laminas.dev/t/about-form-error-is-it-possible-to-add-a-certain-class-like-invalid-on-the-input-select-raido-itself/2483/1 "2021-09-02T08:42:50Z")

</div>

from this document [formElementErrors - laminas-form - Laminas Docs](https://docs.laminas.dev/laminas-form/v3/helper/form-element-errors/)  
I learn to write my own form error helper.

However I have a special requirement that, I need to add a special class like ‘invalid’ on the form element itself, for example onside the input element, not after it. Is it possible to fulfil?

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [September 2, 2021, 10:12am UTC](https://discourse.laminas.dev/t/about-form-error-is-it-possible-to-add-a-certain-class-like-invalid-on-the-input-select-raido-itself/2483/2 "2021-09-02T10:12:41Z")

</div>

If you use the “FormRow” help and there are errors, the class `input-error` is already set.  
This can be customised in a view-script via:

```php
$this->formRow()->setInputErrorClass('is-invalid');

```

Which form view helpers do you use?

---

<div class="post-metadata">

**Author:** ![jobsfan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/jobsfan/32/399_2.png) [@jobsfan](https://discourse.laminas.dev/u/jobsfan)\
**Post date:** [September 3, 2021, 1:52am UTC](https://discourse.laminas.dev/t/about-form-error-is-it-possible-to-add-a-certain-class-like-invalid-on-the-input-select-raido-itself/2483/3 "2021-09-03T01:52:16Z")

</div>

I usually use this way `<div class="hcs-inner-col2"><?= $this->formInput($this->form->get('accountname')); ?></div>`

So this way, it won’t add **input-error** to input element itself?  
What’s the differences between **$this-\>formRow()** and **$this-\>formInput()**.

By the way, I usually use the form like follow to built my form elment:

```auto
    $this->add([
            'name' => 'servername', 
            'type' => Text::class,
            'attributes' => [
                'id' => 'servername',
                'placeholder' => 'pls add a servername',
            ],
        ]);

```

It is possible to add errorclass here? ok forget about it, I can change the invalid class to input-error.

So it is possible to show the input-error when I use this way `<div class="hcs-col2"><?= $this->formInput($this->form->get('servername')); ?></div>`
