# Plugin: Formular erstellen / CSRF

**URL:** https://forum.shopware.com/t/plugin-formular-erstellen-csrf/59202
**Category:** Programmierung
**Created:** [23. April 2019 um 12:13 UTC](https://forum.shopware.com/t/plugin-formular-erstellen-csrf/59202 "2019-04-23T12:13:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![paddelboot](https://avatars.discourse-cdn.com/v4/letter/p/e95f7d/32.png) [@paddelboot](https://forum.shopware.com/u/paddelboot)
#### Post date: [23. April 2019 um 12:13 UTC](https://forum.shopware.com/t/plugin-formular-erstellen-csrf/59202/1 "2019-04-23T12:13:40Z")

</div>

Hallo,

Für mein Plugin versuche ich, ein Suchformular zu erstellen, dessen Eingaben für eine Anfrage an eine entfernte REST API verwendet werden.

Ich finde nicht viel Infos zum Erstellen solcher Formulare in der Dokumentation, bin aber über folgenden Satz gestolpert:

“If you are not using jQuery in your plugin, you have to manually call `CSRF.updateForms()` after you’ve created a new form or replaced some parts of a view which contain a form.” (Quelle: [CSRF Protection](https://developers.shopware.com/developers-guide/csrf-protection/))

Was ist hier mit “not using jQuery in your plugin” gemeint? Wenn ich jQuery “benutze”, würden meine Formulare automatisch mit einem CSRF-Layer versehen? “In addition, every request made by jQuery will be extended with a new header named `X-CSRF-Token`, which includes the received token.” Sprechen wir hier von einem asynchronen Senden eines Formulars mit jQuery? Gibt es dazu in der Dokumentation nähere Infos?

&nbsp;

Danke & Grüße,

Paddelboot

---

<div class="post-metadata">

### Author: ![paddelboot](https://avatars.discourse-cdn.com/v4/letter/p/e95f7d/32.png) [@paddelboot](https://forum.shopware.com/u/paddelboot)
#### Post date: [23. April 2019 um 12:36 UTC](https://forum.shopware.com/t/plugin-formular-erstellen-csrf/59202/2 "2019-04-23T12:36:52Z")

</div>

Derzeit verwende ich folgenden JS-Code:

&nbsp;

```
 $( document ).ready( function () { if ( $( 'form#ersatzteilsuche' ).length ) { console.log( 'adding CSRF' ); CSRF.updateForms(); } } );

```

Ich erhalte die Meldung in der Console, die Funktion `CSRF.updateForms()` wird also ausgeführt. Anders als erwartet wird aber kein verstecktes CSRF-Inputfeld im Formular erzeugt. Kennt jemand den Grund?

Grüße,

Paddelboot

&nbsp;

---

<div class="post-metadata">

### Author: ![paddelboot](https://avatars.discourse-cdn.com/v4/letter/p/e95f7d/32.png) [@paddelboot](https://forum.shopware.com/u/paddelboot)
#### Post date: [23. April 2019 um 12:52 UTC](https://forum.shopware.com/t/plugin-formular-erstellen-csrf/59202/3 "2019-04-23T12:52:54Z")

</div>

Das Problem war das `action` - Attribut meines Suchformulars. Dieses war leer, muss aber offenbar mit einer lokalen URL bestückt werden, also zB. `http://meinshop.de/meinesuche`.

Vielleicht hilft es ja jemandem.
