Try scriptmonkey, he's our resident API expert.
Hi All,
Does anyone have a solution for a wordpress based site that needs to do an automated HTTP post of a web generated lead (with only a couple of form variables, such as name, phone, email, etc) to an API when leads are generated.
Been searching around for some code, but I'm drawing a blank big time. I'm no expert coder but if someone had a code base, I'm sure I could work it out.
Thanks,
Mike
Try scriptmonkey, he's our resident API expert.
So, if I have you right, you have a form on a WP install, from which you want to send the results to an API?
The trouble with the rat race is that even if you win you're still a rat.
Time passes. Listen. Time passes. Dylan Thomas
Ebay Alerts to your inbox
I suggest this:
Create a new template for WP, add all the interaction required in the head of the new template (I'd use cURL to post the details to the API), add a hidden field to the form so that the cURL part is only called when the hidden field is set as a $_POST variable, use that template for the form.
That kind of thing.PHP Code:define('POSTURL', 'http://www.servername.com/APIpage.aspx');
if(isset($_POST['Email'])) $Email = $_POST['Email'];
if(isset($_POST['Name'])) $Name = $_POST['Name'];
// etc.
define('POSTVARS', 'Name=$Name&Email=$Email');
$ch = curl_init(POSTURL);
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,POSTVARS);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,0);
curl_exec($ch);
curl_close($ch);
The trouble with the rat race is that even if you win you're still a rat.
Time passes. Listen. Time passes. Dylan Thomas
Ebay Alerts to your inbox
keano (21-01-11)
Thanks very much for your help - much appreciated!
I told you he was our expert!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks