# Forms, do they work?

**URL:** <https://discourse.getcockpit.com/t/forms-do-they-work/158>\
**Category:** Support\
**Created:** [July 18, 2018, 6:35am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158 "2018-07-18T06:35:07Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![jesperlandberg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jesperlandberg/32/60_2.png) [@jesperlandberg](https://discourse.getcockpit.com/u/jesperlandberg)\
**Post date:** [July 18, 2018, 6:35am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/1 "2018-07-18T06:35:07Z")

</div>

Does forms work? is there any examples how to setup a form somewhere? Docs says “Sorry, still in the making…”.

---

<div class="post-metadata">

**Author:** ![mpartipilo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/mpartipilo/32/6_2.png) [@mpartipilo](https://discourse.getcockpit.com/u/mpartipilo)\
**Post date:** [July 24, 2018, 7:45am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/2 "2018-07-24T07:45:23Z")

</div>

I have a good idea of how forms work. I’ll write some documentation.

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [July 25, 2018, 2:24pm UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/3 "2018-07-25T14:24:18Z")

</div>

@mpartipilo this would be awesome, thank you 👌

---

<div class="post-metadata">

**Author:** ![jesperlandberg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jesperlandberg/32/60_2.png) [@jesperlandberg](https://discourse.getcockpit.com/u/jesperlandberg)\
**Post date:** [August 8, 2018, 2:23pm UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/4 "2018-08-08T14:23:34Z")

</div>

Hi, thanks! Is it possible you could show a simple example on how forms work? (using rest)

---

<div class="post-metadata">

**Author:** ![mpartipilo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/mpartipilo/32/6_2.png) [@mpartipilo](https://discourse.getcockpit.com/u/mpartipilo)\
**Post date:** [August 18, 2018, 7:27pm UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/5 "2018-08-18T19:27:27Z")

</div>

It’s done. Go check out the documentation page.

---

<div class="post-metadata">

**Author:** ![jesperlandberg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jesperlandberg/32/60_2.png) [@jesperlandberg](https://discourse.getcockpit.com/u/jesperlandberg)\
**Post date:** [August 23, 2018, 11:13am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/6 "2018-08-23T11:13:29Z")

</div>

Thanks a lot:)

Btw, does this look correct? I’m getting a 404 on the postUrl.

```
		postForm() {
			const formData = new FormData(this.$refs.contactForm)
			const postUrl = `${this.cockpit.apiUrl}/forms/submit/Contact?token=${this.cockpit.apiToken}`

      		axios.post(postUrl, formData, {
				headers: { 'Content-Type': 'application/json' },
			}).then((response) => {
				console.log('response: ', JSON.stringify(response, null, 2))
			}).catch((error) => {
                console.log(error)
                console.log(formData)
            })
		}
```

---

<div class="post-metadata">

**Author:** ![mpartipilo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/mpartipilo/32/6_2.png) [@mpartipilo](https://discourse.getcockpit.com/u/mpartipilo)\
**Post date:** [August 23, 2018, 11:42am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/7 "2018-08-23T11:42:31Z")

</div>

At a glance, it looks ok.

Let me look for a working example code using axios.

---

<div class="post-metadata">

**Author:** ![mpartipilo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/mpartipilo/32/6_2.png) [@mpartipilo](https://discourse.getcockpit.com/u/mpartipilo)\
**Post date:** [August 23, 2018, 12:35pm UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/8 "2018-08-23T12:35:32Z")

</div>

This is how my http request looks from Postman. Axios is not listed in the code generators, but there’s an example with `request`.

```
POST /api/forms/submit/MyCockpitForm?token=mytoken HTTP/1.1
Host: content.mywebsite.com
Content-Type: application/json
Cache-Control: no-cache

{
    "form": {
        "field1": "value3",
        "field2": "value4"
    }
}

```

With request:  
var request = require(“request”);

```
var options = { method: 'POST',
  url: 'http://content.mywebsite.com/api/forms/submit/MyForm',
  qs: { token: 'mytoken' },
  headers: 
   { 'Cache-Control': 'no-cache',
     'Content-Type': 'application/json' },
  body: { form: { field1: 'value3', field2: 'value4' } },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
```

---

<div class="post-metadata">

**Author:** ![jesperlandberg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jesperlandberg/32/60_2.png) [@jesperlandberg](https://discourse.getcockpit.com/u/jesperlandberg)\
**Post date:** [August 23, 2018, 6:55pm UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/9 "2018-08-23T18:55:59Z")

</div>

thanks, seems my url is wrong in some way but can’t understand what. I can’t access my form json in the browser with:  
`https://example.com/cockpit/api/forms/get/Contact?token=mytoken`

It returns path not found. The exact url structure works for singletons and collections.

EDIT: Nevermind, works now after i did the correct form data structure according to the docs.

Thanks a lot for the docs:)

---

<div class="post-metadata">

**Author:** ![mpartipilo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/mpartipilo/32/6_2.png) [@mpartipilo](https://discourse.getcockpit.com/u/mpartipilo)\
**Post date:** [August 24, 2018, 7:17am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/10 "2018-08-24T07:17:00Z")

</div>

@artur I was checking the code and it looks like API support in forms is limited to submit only. Can you confirm this?

I could not determine if there is an API to show the form’s entries.

---

<div class="post-metadata">

**Author:** ![artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/artur/32/4_2.png) [@artur](https://discourse.getcockpit.com/u/artur)\
**Post date:** [August 24, 2018, 9:37am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/11 "2018-08-24T09:37:32Z")

</div>

yes, you’re right. the forms api only supports submits

---

<div class="post-metadata">

**Author:** ![adrigm](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/adrigm/32/81_2.png) [@adrigm](https://discourse.getcockpit.com/u/adrigm)\
**Post date:** [August 28, 2018, 11:20am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/12 "2018-08-28T11:20:08Z")

</div>

Hello,

How can I receive the forms in my email?

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [August 30, 2018, 10:16am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/13 "2018-08-30T10:16:13Z")

</div>

I believe you can set up a webhook? Or you can go programmatically and implement a “forms.save.after” hook in a custom addon, I did something similar in the past for collections in that addon - [https://github.com/pauloamgomes/cockpit-EmailOnSave](https://github.com/pauloamgomes/cockpit-EmailOnSave)

---

<div class="post-metadata">

**Author:** ![jesperlandberg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jesperlandberg/32/60_2.png) [@jesperlandberg](https://discourse.getcockpit.com/u/jesperlandberg)\
**Post date:** [September 3, 2018, 7:35pm UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/14 "2018-09-03T19:35:10Z")

</div>

I can see my form entries, but I’m not getting any emails. Isn’t it enough to fill my email under “email” when editing the form?

---

<div class="post-metadata">

**Author:** ![PurpleEdge2214](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/purpleedge2214/32/132_2.png) [@PurpleEdge2214](https://discourse.getcockpit.com/u/PurpleEdge2214)\
**Post date:** [October 24, 2018, 1:49am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/15 "2018-10-24T01:49:27Z")

</div>

Doesn’t it make sense to be able to GET form entries?

---

<div class="post-metadata">

**Author:** ![mpartipilo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/mpartipilo/32/6_2.png) [@mpartipilo](https://discourse.getcockpit.com/u/mpartipilo)\
**Post date:** [February 28, 2019, 10:24am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/16 "2019-02-28T10:24:53Z")

</div>

Checking the code I see that an endpoint was added: /api/forms/export/{form\_name}?token=xxx

---

<div class="post-metadata">

**Author:** ![mpartipilo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/mpartipilo/32/6_2.png) [@mpartipilo](https://discourse.getcockpit.com/u/mpartipilo)\
**Post date:** [February 28, 2019, 10:30am UTC](https://discourse.getcockpit.com/t/forms-do-they-work/158/17 "2019-02-28T10:30:34Z")

</div>

I like the idea of making the forms a proxy for a collection.

Mostly because I’d like to have pagination and validation in the call to retrieve form entries, instead of having to retrieve the whole list of entries with a single call.
