# CSRF validator error

**URL:** <https://discourse.laminas.dev/t/csrf-validator-error/2740>\
**Category:** Components & MVC\
**Tags:** laminas-validator\
**Created:** [January 26, 2022, 8:42pm UTC](https://discourse.laminas.dev/t/csrf-validator-error/2740 "2022-01-26T20:42:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kriss\_Kals](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/kriss_kals/32/1295_2.png) [@Kriss\_Kals](https://discourse.laminas.dev/u/Kriss_Kals)\
**Post date:** [January 26, 2022, 8:42pm UTC](https://discourse.laminas.dev/t/csrf-validator-error/2740/1 "2022-01-26T20:42:47Z")

</div>

Hello,

I have a problem with overwriting the message returned when a csrf element is incorrectly validated.

When the element name is other than csrf e.g. post\_csfr I keep getting the error “The form submitted did not originate from the expected site”.

```auto

[
                'name' => 'post_csrf',
                'required' => true,
                'filters' => [
                    ['name' => \Laminas\Filter\StripTags::class],
                    ['name' => \Laminas\Filter\StringTrim::class],
                ],
                'validators' => [
                    [
                        'name' => \Laminas\Validator\NotEmpty::class,
                    ],
                    [
                        'name' => \Laminas\Validator\Csrf::class,
                        'options' => [
                            'messages' => [
                                \Laminas\Validator\Csrf::NOT_SAME => 'my error message',
                            ],
                        ],
                    ],
                ],
            ],

```

Is this part of the code correct/allowed (I get the expected result when the input name is “csrf”):

```auto
[
      'name' => \Laminas\Validator\Csrf::class,
      'options' => [
            'messages' => [
                 \Laminas\Validator\Csrf::NOT_SAME => 'my error message',
            ],
      ],
],

```

---

<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:** [January 26, 2022, 9:36pm UTC](https://discourse.laminas.dev/t/csrf-validator-error/2740/2 "2022-01-26T21:36:00Z")

</div>

> [@Kriss\_Kals](#):
>
> When the element name is other than csrf e.g. post\_csfr

You can set a name via the options:

```php
[
      'name' => \Laminas\Validator\Csrf::class,
      'options' => [
            'name' => 'post_csfr',
            'messages' => [
                 \Laminas\Validator\Csrf::NOT_SAME => 'my error message',
            ],
      ],
],

```

---

<div class="post-metadata">

**Author:** ![Kriss\_Kals](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/kriss_kals/32/1295_2.png) [@Kriss\_Kals](https://discourse.laminas.dev/u/Kriss_Kals)\
**Post date:** [January 26, 2022, 10:08pm UTC](https://discourse.laminas.dev/t/csrf-validator-error/2740/3 "2022-01-26T22:08:00Z")

</div>

@froschdesign  
Your hint solved the problem. I did not find this in the documentation. Thank you very much! 🙂

---

<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:** [January 27, 2022, 11:48am UTC](https://discourse.laminas.dev/t/csrf-validator-error/2740/4 "2022-01-27T11:48:51Z")

</div>

As already mentioned in the chat: Please [create an issue report](https://github.com/laminas/laminas-validator/issues) for this problem or create a pull request to solve the problem directly. Thanks in advance! 👍🏼
