Sending web form data to leads module with cURL

Good afternoon everyone,

I’m having the following problem:

I have a web form to capture leads.
Suite crm gives me the option to send those leads to the module through the web to module form but that form only accepts an action attribute.
My form on the landing page uses a php script to:
1 save the data to a db,
2 send an email with the data
3 perform the marketing campaign conversion

I have tried to send the data to the entry point of the leads module by post request but it gives me a CORS error, so I decided to make a PHP script to send the form data using cURL. the script is as follows:

$ URL = “the url of the module entry point”;
$ USER = “Mozilla / 5.0 (Macintosh; Intel Mac OS X 10.9; rv: 50.0) Gecko / 20100101 Firefox / 50.0”;
$ ENC = “Content-type: multipart / form-data”;
$ handler = curl_init ($ URL);

$ formdata = file_get_contents (“php: // input”);
$ data = json_decode ($ formdata);

$ lead is an array with the fields in format: ‘field’ => value, where value is: $ value = $ data-> field

curl_setopt ($ handler, CURLOPT_USERAGENT, $ USER);
curl_setopt ($ handler, CURLOPT_HTTPHEADER, [$ ENC]);
curl_setopt ($ handler, CURLOPT_CONNECTTIMEOUT, 100);
curl_setopt ($ handler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ handler, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ handler, CURLOPT_HEADER, true);
curl_setopt ($ handler, CURLOPT_POST, true);
curl_setopt ($ handler, CURLOPT_POSTFIELDS, $ lead);

$ post_data = curl_exec ($ handler);

curl_close ($ handler);

the problem is that the leads are not loaded. for some reason the crm is not understanding the data correctly

I think this is a very common problem and that many users have, however there is no information about it.
Thank you
Best regards
Pablo Pimas


my advice would be to just use the normal web-to-person form that SuiteCRM provides.

Then you add a logic hook on Leads module, after_save hook, and do any additional processing in there (call other systems, etc)

but that is not possible, because I have to redo the whole site. It is also made with angular forms that do not use the action attribute. The truth is that the crm integration system in this sense is quite limited and rigid. I am trying to trick the PHPSESSID cookie that is causing the problem, I do not have much knowledge of curl or php so if anyone knows how to do it thank you very much.
thanks anyway for your advice

Have you considered using the API to add the Lead?

not really. I wouldn’t even know where to start. can you give me any idea how to use it? thanks

:-o, I must to learn entire development stuff in PHP.
I think that I can do my own entire crm app in javascript fastest :slight_smile:
Thank you very much for your support anyway

Pablo, Did you make any progress? I’ve been working on this for the last couple days with Gravity Forms Webhooks add on. Running into a cURL 60 error but wanted to see how you did with this. Appreciated

Finally I discarded curl and php. I solved it with a javascript function that takes the data from the form and makes the post to the crm with XHR in formData formar. I did it in a webapp with angular with reactive forms. I also had to adjust the CORS. If you want I can show you the code. Regards

I finally got this working with cURL using Gravity Forms Webhooks add-on, on WordPress to send an email to admin or whoever I choose, log the entry on the back-end,and of course create an entry into the Leads Module of SuiteCRM.

So happy because going forward with everything you can do with Gravity Forms versus the CRM generates forms, merge tags etc makes it so easy to manipulate the data with the Webhooks add-on. If anything needs to be changed in the future no problem so simple with the web hooks interface.

For me I kept running into the curl error 60 in that it could not retrieve the SSL certificate from the local issuer but since the CRM generated forms doesn’t require that anyway it’s not necessary but default by the web hooks add-on as I could see in the code. So I just added the following to the functions file and makes everything good to go. I hope this helps someone else out there because I googled and search for days without a solution.

function my_gravitity_forms_request_filter($args) {
    $args['sslverify'] = false;
    return $args;

add_filter( 'gform_webhooks_request_args', 'my_gravitity_forms_request_filter', 10, 1);
1 Like

Hey ChrisRyan, would you be able to share a screenshot of how you set up the Gravity Forms Web Hook Add on? I’m messing around with it trying to get it to work as well.

So I understand you need to add the function, but what are you using as your settings in the GF plugin?