Results 1 to 3 of 3

Thread: Using Curl to submit to WebToLeadCapture.php

  1. #1
    westbym is offline Junior Member
    Join Date
    Mar 2007
    Posts
    2

    Default Using Curl to submit to WebToLeadCapture.php

    I need to submit my web form to two different places. I have used the below code to do this successfully to the first. But Sugar doesnt seem to like it. I just get the error message :
    "We are sorry, the server is currently unavailable, please try again later."
    If anyone can help that would be great. I can't think of any reason why its not working. Using a normal form that submits to WebToLeadCapture.php works fine.

    PHP Code:
    $post_array2 = array(
    "campaign_id" => "77961414-1638-d7ab-cdf0-45fefbe0131c",
    "redirect_url" => "http://google.com",
    "assigned_user_id" => "1",
    "req_id" => "last_name;",
    "last_name" => "farty",
    "phone_home" => "2323323323",
    "Submit" => "Submit"
        
    );
    $post_data2 http_build_query($post_array2);
    $url2 "http://d36349.u30.m8solutions.com/WebToLeadCapture.php";
    $ch2 curl_init();    // initialize curl handle
    curl_setopt($ch2CURLOPT_URL,$url2); // set url to post to
    curl_setopt($ch2CURLOPT_FAILONERROR1);
    curl_setopt($ch2CURLOPT_FOLLOWLOCATION1);// allow redirects
    curl_setopt($ch2CURLOPT_RETURNTRANSFER,1); // return into a variable
    curl_setopt($ch2CURLOPT_TIMEOUT3); // times out after 4s
    curl_setopt($ch2CURLOPT_POST1); // set POST method
    curl_setopt($ch2CURLOPT_POSTFIELDS$post_data); // add POST fields
    $result curl_exec($ch2); // run the whole process
    curl_close($ch2);
    echo 
    $result
    Matt

  2. #2
    ErkanG is offline Junior Member
    Join Date
    Nov 2008
    Posts
    1

    Thumbs up Re: Using Curl to submit to WebToLeadCapture.php

    hi westbym,

    I had the same problem, here is how I solved;

    Due to some ongoing bugs in my edition (workflow email alert), I needed to take care of all the lead notification from my form page, at the same time write to SugarCRM as a lead.

    So my form's action is itself as "myform.php?complete", and the PHP is taking care of the responding with email, and all of the needed fields are stated in html inside form tags.

    I have tried to post stating an array like you do, but no matter how I try I was getting the same error as you do. So while checking the posted array with
    PHP Code:
    print_r($_POST); 
    no matter which fileds I deleted from my array I was having the same results on my debug print. So instead of using the array, I tried to post with
    PHP Code:
    curl_setopt($chCURLOPT_POSTFIELDS$_POST); 
    ta-da! it worked.

    Below you can find my code working for myform.php;

    PHP Code:
    //
    // test HTTP POST submitter, using “libcurl”
    //
    // the target URL which contains scripts that accepts post request
    $url "http://mysite.sugarondemand.com/index.php?entryPoint=WebToLeadCapture";
    $ch curl_init();
    // set the target url
    curl_setopt($chCURLOPT_URL,$url);
    // howmany parameter to post
    curl_setopt($chCURLOPT_POST1);
    curl_setopt($ch2CURLOPT_FAILONERROR1); 
    // allow redirects 
    curl_setopt($ch2CURLOPT_FOLLOWLOCATION1);
    // HERE YOU MUST SET THE VARIABLES FROM THE FORM
    curl_setopt($chCURLOPT_POSTFIELDS$_POST);
    // execute curl,fetch the result and close curl connection
    $resultcurl_exec ($ch);
    curl_close ($ch);

    //after finishing your job you may wish to check the parameters and result
     
    print_r($result);
     
    print_r($_POST); 
    My SugarCRM info;
    Sugar Edition: Professional
    Sugar Version: Version 5.1.0b (Build 4905)
    Deployment Option: On-Demand

    erkan
    Last edited by ErkanG; 2008-12-11 at 09:04 PM. Reason: deleted redundant commented out code

  3. #3
    ForgeTech is offline Junior Member
    Join Date
    Mar 2010
    Posts
    1

    Default Re: Using Curl to submit to WebToLeadCapture.php

    My issue is that I need to fill in a form, and that gets passed to another page with some more forms that needs to be filled in.

    On the second page you can get a variety of forms depending on which values you selected on the 1st page.
    i need to post the data to sugar and still be on the page so that you can fill in the new forms.

    only problem is that you cannot be redirected to the correct form by coping the URL and pasting it.... something funny that prohibits it.

    Anyway..
    what do i need to do to cURL data into Sugar on my local server. it has a public IP that works

    //POSTING INTO SUGAR

    $lead_source = "Web Site";
    $user = "my_lead_capture_form";
    $emailAddress0 = $_REQUEST[emailAddress0];
    $first_name = $_REQUEST[first_name];
    $account_name = "F Business";
    $phone_work = $_REQUEST[phone_work];
    $website_c = $_REQUEST[website_c];
    $redirect = "";

    //set POST variables
    $postURL = 'http://crm.myserver.com/sugar/leadCapture.php';
    //$postURL = 'http://insight:81/sugar/leadCapture.php?';
    $Url = $postURL;

    //curl try 2
    $fields = array(
    "lead_source"=> $lead_source,
    "user"=> $user,
    "redirect"=> $redirect,
    "first_name"=> $first_name,
    "emailAddress0"=> $emailAddress0,
    "account_name"=> $account_name,
    "phone_work"=> $phone_work,
    "website_c"=> $website_c
    );
    //-------------ECHO----------var_dump($fields);
    //-------------ECHO----------echo "<br><br><br><br> 1st" . $postURL . "<br><br><br><br><br><br>";
    //url-ify the data for the POST
    foreach($fields as $key=>$value)
    { $fields_string .= $key.'='.urlencode($value).'&'; }
    $fields_string = rtrim($fields_string,'&');
    //echo $fields_string;
    $postURL = $postURL.$fields_string;
    //echo $postURL;

    ////CURL OPTION 1
    // // is curl installed?
    // if (!function_exists('curl_init'))
    // {
    // die('CURL is not installed!');
    // }
    // // create a new curl resource
    // $ch = curl_init();
    //
    //// Here you find more options for curl:
    //// http://www.php.net/curl_setopt
    ////
    //
    // // set URL to download
    // curl_setopt($ch, CURLOPT_URL, $Url);
    // // set data to post
    // curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    // // set referer:
    // curl_setopt($ch, CURLOPT_REFERER, "http://www.forgebusiness.com/");
    // // remove header? 0 = yes, 1 = no
    // curl_setopt($ch, CURLOPT_HEADER, 0);
    // // should curl return or print the data? true = return, false = print
    // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // // timeout in seconds
    // curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    // // download the given URL, and return output
    // $output = curl_exec($ch);
    // // close the curl resource, and free system resources
    // curl_close($ch);
    // return $output;

    //CURL option 2
    // the target URL which contains scripts that accepts post request
    $url = "http://crm.forgebusiness.com/sugar/index.php?entryPoint=WebToLeadCapture";
    $ch = curl_init();
    // set the target url
    curl_setopt($ch, CURLOPT_URL,$Url);
    // howmany parameter to post
    curl_setopt($ch, CURLOPT_POST, 1);
    //curl_setopt($ch2, CURLOPT_FAILONERROR, 1);
    // allow redirects
    //curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1);
    // HERE YOU MUST SET THE VARIABLES FROM THE FORM
    curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
    // execute curl,fetch the result and close curl connection
    $result= curl_exec ($ch);
    curl_close ($ch);

    i have echoed all my variables in the array and its working, i used this exact piece of cURL script previously and it worked.

    is there something funny that needs to be done to cURL into sugar?
    I cannot use the $_POST variable and send everything because the data gets used for other things and i cannot just pass it like that. what can I do to use an array?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Re-compiling PHP with --cURL
    By ruediger in forum Installation and Upgrade Help
    Replies: 5
    Last Post: 2006-11-20, 07:52 PM
  2. IMAP and CURL not found
    By khinester in forum Help
    Replies: 10
    Last Post: 2006-10-31, 06:24 AM
  3. cURL Libraryn asennus
    By planewalker in forum Finnish
    Replies: 2
    Last Post: 2006-04-05, 05:39 PM
  4. Error with cURL (email settings...)
    By thomavista in forum Help
    Replies: 2
    Last Post: 2006-01-19, 09:31 PM
  5. Replies: 2
    Last Post: 2005-12-28, 01:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •