# Custom form error message - aria

**URL:** <https://discourse.cakephp.org/t/custom-form-error-message-aria/9643>\
**Category:** Need Help\
**Created:** [August 18, 2021, 5:16am UTC](https://discourse.cakephp.org/t/custom-form-error-message-aria/9643 "2021-08-18T05:16:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [August 18, 2021, 5:16am UTC](https://discourse.cakephp.org/t/custom-form-error-message-aria/9643/1 "2021-08-18T05:16:59Z")

</div>

Is it possible to modify the form’s own error message so that some parameters are added?

```auto
<form>
	<label for="name">Name</label>
	<input name="name" id="name" type="text" required>
	<div class="error-message">Fill the name</div>
</form>

```

I want it to be

```auto
<form>
	<label for="name">Name</label>
	<input name="name" id="name" type="text" aria-required="true" aria-invalid="true" aria-describedby="hint-name" required>
	<div class="error-message" id="hint-name">Fill the name</div>
</form>

```

It is important to put the ID in the `error-message`, for aria.

FormHelper contain template:

```auto
'error' => '<div class="error-message">{{content}}</div>',

```

Thank you for help

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [August 18, 2021, 8:03pm UTC](https://discourse.cakephp.org/t/custom-form-error-message-aria/9643/2 "2021-08-18T20:03:42Z")

</div>

You should look at [Form - 4.x](https://book.cakephp.org/4/en/views/helpers/form.html#customizing-the-templates-formhelper-uses)

See [cakephp/FormHelper.php at master · cakephp/cakephp · GitHub](https://github.com/cakephp/cakephp/blob/master/src/View/Helper/FormHelper.php#L88) for all the templates/keys which can be overwritten.

The problem you are running into is the fact, that the default `error` template doesn’t have any other “variables” which can be used inside the template.

> <https://github.com/cakephp/cakephp/blob/master/src/View/Helper/FormHelper.php#L769>

This line only sets the `content` variable which then will be output at the position of `{{content}}` in this template.

> <https://github.com/cakephp/cakephp/blob/master/src/View/Helper/FormHelper.php#L98>

So in your example you would have to extend the FormHelper with a custom class, overwrite the error function and add that functionality in there.

I haven’t thought it completely through but those are the code parts you need to start looking at to get to know how this whole system works.

---

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [August 19, 2021, 6:03am UTC](https://discourse.cakephp.org/t/custom-form-error-message-aria/9643/3 "2021-08-19T06:03:45Z")

</div>

Thank you, and how can you overwrite the error function, can you please give an example?

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [August 19, 2021, 3:47pm UTC](https://discourse.cakephp.org/t/custom-form-error-message-aria/9643/4 "2021-08-19T15:47:33Z")

</div>

look at [forms - cakephp 3: change class input error - Stack Overflow](https://stackoverflow.com/questions/29982791/cakephp-3-change-class-input-error)
