Send values to form

forms

#1

Hi everyone, i hope that someone could help me.

i have the next code:
$str_post = "email=" . urlencode($variables_lectura["email"]) . "&codigo_promocional=" . urlencode($variables_lectura["codigo_promocional"]) . "&firstname=" . urlencode($variables_lectura["firstname"]) .
"&phone=" . urlencode($variables_lectura["phone"]) . "&fecha_nacimiento=" . urlencode($variables_lectura["fecha_nacimiento"]) . "&sexo=" . urlencode($variables_lectura["sexo"]) .
"&address=" . urlencode($variables_lectura["address"]) . "&zip=" . urlencode($variables_lectura["zip"]) . "&city=" . urlencode($variables_lectura["city"]). "&state=" . urlencode($variables_lectura["state"])
."&country=" . urlencode($variables_lectura["country"]). "&tags=" . urlencode($variables_lectura["tags"]). "&fecha_creacion=" . urlencode($variables_lectura["fecha_creacion"]).
"&condiciones=" . urlencode($variables_lectura["condiciones"]). "&completa_id_dni=" . urlencode($variables_lectura["completa_id_dni"]). "&motivo_no_trabajo=" . urlencode($variables_lectura["motivo_no_trabajo"]).
"&tipo_contrato=" . urlencode($variables_lectura["tipo_contrato"]). "&company=" . urlencode($variables_lectura["company"]). "&job_title=" . urlencode($variables_lectura["job_title"]).
"&annual_revenue=" . urlencode($variables_lectura["annual_revenue"]). "&inversion_inf_300=" . urlencode($variables_lectura["inversion_inf_300"]).
"&patrimonio_trabajo=" . urlencode($variables_lectura["patrimonio_trabajo"]). "&residencia_unica_nacional=" . urlencode($variables_lectura["residencia_unica_nacional"]).
"&responsabilidad_publica=" . urlencode($variables_lectura["company"]). "&us_person=" . urlencode($variables_lectura["us_person"]). "&mobile_phone=" . urlencode($variables_lectura["mobile_phone"]).
"&estado_civil=" . urlencode($variables_lectura["estado_civil"]). "&tipo_actividad=" . urlencode($variables_lectura["tipo_actividad"]). "&sector=" . urlencode($variables_lectura["sector"]) .
"&origen=" . urlencode($variables_lectura["origen"]);

$endpoint ="https://forms.hsforms.com/submissions/v3/public/submit/formsnext/multipart/portalid/formid";
$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;
echo "<br>".$str_post;

Actually, i've copied this code from "https://developers.hubspot.com/docs/methods/forms/submit_form" and this should send the values inside str_post to the form, however it is not happens. what's wrong?

Thanks


#2

Hi @franciscobonillo,

That doesn't appear to be the correct form submission endpoint. The form submission endpoint is

https://forms.hubspot.com/uploads/form/v2/:portal_id/:form_guid
But in your code, you specify $endpoint as:

https://forms.hsforms.com/submissions/v3/public/submit/formsnext/multipart/portalid/formid

Can you try posting your request to the endpoint provided in the 'Submit a from' endpoint doc?


#3

Hi @Derek_Gervais, i know, A little bit after I wrote it, I made several tests and that was wrong, now it works.
Thank you handsome.