# Form API cannot populate information

**URL:** <https://community.hubspot.com/t/form-api-cannot-populate-information/15295>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [July 15, 2019, 12:41am UTC](https://community.hubspot.com/t/form-api-cannot-populate-information/15295 "2019-07-15T00:41:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zendersto](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zendersto/32/9140_2.png) [@zendersto](https://community.hubspot.com/u/zendersto)\
**Post date:** [July 15, 2019, 12:41am UTC](https://community.hubspot.com/t/form-api-cannot-populate-information/15295/1 "2019-07-15T00:41:29Z")

</div>

Hi ive been using the form API to connect the data to Hubspot, im using PHP. Im testing the integration with a simple form via xampp.

when I hit submit button with POST method, the form only sent to hubspot what page the data was sent from but not the information of the users.

the code throws me an error with unknown hubspotutk so im quite sure it has something to do with cookie but i have no idea how to fix it.

here is my html form:

```auto
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<form action="hubspot.php" method="post">
 First name:<br>
 <input type="text" name="firstname"><br>
 Last name:<br>
 <input type="text" name="lastname" ><br>
 Email:<br>
 <input type="email" name="email" ><br><br>
 <input type="submit" value="Submit">
</form>

</body>
</html>

```

and here is my PHP code:

```auto
<?php
 //Process a new form submission in HubSpot in order to create a new Contact.
$firstname = $lastname = $email ="";
$hubspotutk = $_COOKIE['hubspotutk']; //grab the cookie from the visitors browser.
$ip_addr = $_SERVER['REMOTE_ADDR']; //IP address too.
$hs_context = array(
 'hutk' => $hubspotutk,
 'ipAddress' => $ip_addr,
 'pageUrl' => 'http://localhost/mother.html',
 'pageName' => 'Zen Test'
);
$hs_context_json = json_encode($hs_context);

//Need to populate these variable with values from the form.
$str_post = "firstname=" . urlencode($firstname)
 . "&lastname=" . urlencode($lastname)
 . "&email=" . urlencode($email)
 . "&hs_context=" . urlencode($hs_context_json); //Leave this one be

//replace the values in this URL with your portal ID and your form GUID
$endpoint = 'https://forms.hubspot.com/uploads/form/v2/6123547/0051538d-2665-4988-8a18-2c449de75ae3';

$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array(
 'Content-Type: application/x-www-form-urlencoded'
));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch); //Log the response from HubSpot as needed.
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code
@curl_close($ch);
echo $status_code . " " . $response;

?>

```

what am i missing ?

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [July 15, 2019, 5:31am UTC](https://community.hubspot.com/t/form-api-cannot-populate-information/15295/2 "2019-07-15T05:31:20Z")

</div>

Hello @zendersto

It seems that the code that you have used for the form submission is working fine. The only thing that I have noticed in the code snippet is that you have made the email variable empty ( “” ) string and it can be cause of in proper data.  
Try once with valid email value and it will work for sure.

Thanks

---

<div class="post-metadata">

**Author:** ![zendersto](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zendersto/32/9140_2.png) [@zendersto](https://community.hubspot.com/u/zendersto)\
**Post date:** [July 15, 2019, 6:48am UTC](https://community.hubspot.com/t/form-api-cannot-populate-information/15295/3 "2019-07-15T06:48:30Z")

</div>

Hi thanks for your response,

I replaced the variables now the code works fine and successfully capture the data and send to hubspot. However, it still throws me an error with hubspotutk, looks like I have to add something to the cookie ? can you help

```auto
<?php
 //Process a new form submission in HubSpot in order to create a new Contact.

$hubspotutk = $_COOKIE['hubspotutk']; //grab the cookie from the visitors browser.
$ip_addr = $_SERVER['REMOTE_ADDR']; //IP address too.
$hs_context = array(
 'hutk' => $hubspotutk,
 'ipAddress' => $ip_addr,
 'pageUrl' => 'http://localhost/mother.html',
 'pageName' => 'Zen Test'
);
$hs_context_json = json_encode($hs_context);

//Need to populate these variable with values from the form.
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email= $_POST["email"];
$str_post = "firstname=" . urlencode($firstname)
 . "&lastname=" . urlencode($lastname)
 . "&email=" . urlencode($email)
 . "&hs_context=" . urlencode($hs_context_json); //Leave this one be

//replace the values in this URL with your portal ID and your form GUID
$endpoint = 'https://forms.hubspot.com/uploads/form/v2/6123547/0051538d-2665-4988-8a18-2c449de75ae3';

$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array(
 'Content-Type: application/x-www-form-urlencoded'
));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch); //Log the response from HubSpot as needed.
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE); //Log the response status code
@curl_close($ch);
echo $status_code . " " . $response;

?>

```

---

<div class="post-metadata">

**Author:** ![WendyGoh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wendygoh/32/42320_2.png) [@WendyGoh](https://community.hubspot.com/u/WendyGoh)\
**Post date:** [July 15, 2019, 9:00am UTC](https://community.hubspot.com/t/form-api-cannot-populate-information/15295/4 "2019-07-15T09:00:56Z")

</div>

Hi @zendersto,

When looking to use the hubspotutk cookie, you’ve got to first installed the HubSpot tracking code (Learn more here: [Install the HubSpot tracking code](https://knowledge.hubspot.com/articles/kcs_article/reports/install-the-hubspot-tracking-code)). This is because the hubspotutk cookie is placed in the user’s browser by the HubSpot tracking code. This tracking code must be installed on the page that the form is on.

- To verify if the HubSpot tracking code has been installed and that it’s firing correctly, you can refer to this useful documentation: [verify HubSpot tracking code](https://knowledge.hubspot.com/articles/kcs_article/reports/how-do-i-know-if-my-hubspot-tracking-code-is-working).

In this case, could you confirm that with the tracking code present, you’re seeing the error?

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [July 17, 2019, 5:03am UTC](https://community.hubspot.com/t/form-api-cannot-populate-information/15295/5 "2019-07-17T05:03:52Z")

</div>

Hello @zendersto

If you can please write me the specific error that you are getting related to hubspotutk parameter then I can help you better.

Thanks
