# Using cUrl to post data in forms

**URL:** <https://discourse.getcockpit.com/t/using-curl-to-post-data-in-forms/1363>\
**Category:** Support\
**Created:** [April 16, 2020, 10:36am UTC](https://discourse.getcockpit.com/t/using-curl-to-post-data-in-forms/1363 "2020-04-16T10:36:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![howbizarre](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/howbizarre/32/397_2.png) [@howbizarre](https://discourse.getcockpit.com/u/howbizarre)\
**Post date:** [April 16, 2020, 10:36am UTC](https://discourse.getcockpit.com/t/using-curl-to-post-data-in-forms/1363/1 "2020-04-16T10:36:10Z")

</div>

Hello Guys,

I’m trying to send data using **php cUrl** to cockpit form, but nothing happening. The form stays empty.

My test code looks like  
\<?php  
$url = ‘[https://my.site/api/forms/submit/partsForm?token=MyFancyTokenKey](https://my.site/api/forms/submit/partsForm?token=MyFancyTokenKey)’;  
$parts = [‘start’=\>‘Hard’, ‘end’=\>‘Disk’];

```
	$ch = curl_init($url);

	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['parts' => $parts]));
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

	$result = curl_exec($ch);

	curl_close($ch);

```

Do i need to set something in headers or different one to post data to the form?

---

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [April 16, 2020, 12:23pm UTC](https://discourse.getcockpit.com/t/using-curl-to-post-data-in-forms/1363/2 "2020-04-16T12:23:13Z")

</div>

You have to wrap your data in a form object.

```auto
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
  'form' => [
    'parts' => $parts
  ]
]));

```

edit: I’m not very familiar with curl… I would send a json body with the data wrapped in the `form` object. Not sure, if it works with just sending the raw post fields.

---

<div class="post-metadata">

**Author:** ![howbizarre](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/howbizarre/32/397_2.png) [@howbizarre](https://discourse.getcockpit.com/u/howbizarre)\
**Post date:** [April 16, 2020, 12:26pm UTC](https://discourse.getcockpit.com/t/using-curl-to-post-data-in-forms/1363/3 "2020-04-16T12:26:37Z")

</div>

Thank you.  
Everything is working fine now.
