APIs & Integrations

disruptcap
Member

Non HubSpot form doesn't work

My form 
<html>

<head>
<title>Add New Record HubSpot</title>
</head>

<body>

<form method = "post" action = "insert.php">
<table width = "400" border = "0" cellspacing = "1"
cellpadding = "2">

<tr>
<td width = "100">First Name</td>
<td><input name = "fname" type = "text"
id = "fname"></td>
</tr>

<tr>
<td width = "100">Last Name</td>
<td><input name = "lname" type = "text"
id = "lname"></td>
</tr>

<tr>
<td width = "100">Email</td>
<td><input name = "email" type = "email"
id = "email"></td>
</tr>
<tr>
<td width = "100">Phone</td>
<td><input name = "phone" type = "phone"
id = "phone"></td>
</tr>

<tr>
<td width = "100"> </td>
<td> </td>
</tr>

<tr>
<td width = "100"> </td>
<td>
<input name = "add" type = "submit" id = "add"
value = "Submit">
</td>
</tr>

</table>
</form>
</body>
</html>

 

PHP code

<?php

if( isset($_POST['submit']) )
{


$fname=$_POST['fname'];
$lname=$_POST['lname'];
$phone=$_POST['phone'];
$email=$_POST['email'];


$contact_data = array(
"fname" => $fname,
"lname" => $lname,
"email" => $email,
"phone" => $phone
);

$ans_hubspot = new ans_hubspot();
$ans_hubspot->contact_create($contact_data);
//$ans_hubspot->list_create("Recovery Lead Generation");
$ans_hubspot->list_assign_contact("2", $contact_data["phone"]);

}

class ans_hubspot{

private $hapikey = "5ca47a89-800a-4e77-b9c5-ccecd028ab81";

function list_assign_contact($lid, $phone){
(object)$arr = array(
"phone" => array($phone)
);
$post_json = json_encode($arr);
$endpoint = 'https://api.hubapi.com/contacts/v1/lists/'.$lid.'/add?hapikey=' . $this->hapikey;
$this->http($endpoint,$post_json);
}


function list_create($list_name){
$arr = array(
"name" => $list_name,
"dynamic" => false,
"filters" => array(
array(
(object)array(
"operator" => "EQ",
"value" => "@hubspot",
"property" => "twitterhandle",
"type" => "string"
)
)
)
);
$post_json = json_encode($arr);
$endpoint = 'https://api.hubapi.com/contacts/v1/lists?hapikey=' . $this->hapikey;
$this->http($endpoint,$post_json);
}

function contact_create($contact_data){
$arr = array(
'properties' => array(
array(
'property' => 'acceptance',
'value' => "Undecided"
),
array(
'property' => 'phone',
'value' => $contact_data["phone"]
),
array(
'property' => 'email',
'value' => $contact_data["email"]
),
/*array(
'property' => 'lastname',
'value' => $contact_data["lname"]
),*/
array(
'property' => 'firstname',
'value' => $contact_data["fname"]
)

)
);

$post_json = json_encode($arr);
$endpoint = 'https://api.hubapi.com/contacts/v1/contact?hapikey=' . $this->hapikey;
$this->http($endpoint,$post_json);
}

function http($endpoint,$post_json){

$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $post_json);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch);
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errors = curl_error($ch);
@curl_close($ch);
return $response . "<hr>";

}
}

 


?>

 

 

0 Upvotes
1 Reply 1
dennisedson
HubSpot Product Team
HubSpot Product Team

Non HubSpot form doesn't work

Hi @disruptcap ,

Can you provide an error message that you receive?  Do you have a link to the page where this form is being hosted?

Thanks!

0 Upvotes