Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: how to update lead via webform

  1. #1
    scheinarts is offline Sugar Community Member
    Join Date
    Feb 2007
    Location
    Panama City, Panama
    Posts
    151

    Default how to update lead via webform

    I am new to Sugar and have developed interest in further customizing its functions to suit my business needs. I am looking to update an already existing lead via web lead form. Let me explain the reasoning behind this...

    -Person fills out web lead form on my website requesting for an e-brochure (the form only asks for first & last name and email).
    -Person automatically receives email with a specific url link to the ebrochure (i am working on an automated notification script embedded into the web lead form independent from sugar). A lead is created in Sugar with only first and last name and email with Lead Status set to :Ebrochure
    -On the actual brochure, there is a section asking the person if he/she would like this brohure printed and snail mailed to them. A form would be placed here to be filled out. At this point, the first and last name as well as the email should be pre-fillled out in the form (this part I have not idea how to make it happen) I was thinking something like:
    Code:
    <input type="text" name="first_name" id="first_name" value="<?php echo '$first_name'; ?>" />
    -The mailing address needs to be filled out on the form, and this should update the existing lead in Sugar with the address and change the lead status to Pbrochure

    I know this can be achieved using Sugar SOAP but I am having a hard time putting it together. I am wondering is anybody hass done something similar. Any insight on how to do this? Thanks.

    Cheers,

    Allen
    Last edited by scheinarts; 2007-02-19 at 04:15 AM.

  2. #2
    scheinarts is offline Sugar Community Member
    Join Date
    Feb 2007
    Location
    Panama City, Panama
    Posts
    151

    Default Re: how to update lead via webform

    the code I am using the send an automatic email to the person filling out the lead webform is the following

    Code:
    $to = $_REQUEST['email1'] ;
    $from = "ebrochure@yourdomain.com";
    $subject = "Your E-brochure";
    $message = "Thank you for requesting the E-brochure. Click here: http://yahoo.com to view";
    $headers = "From: $from";
    $sent = mail($to, $subject, $message, $headers) ;
    This is placed in webtoleadcapture.php right after require_once('modules/CampaignLog/CampaignLog.php');

  3. #3
    scheinarts is offline Sugar Community Member
    Join Date
    Feb 2007
    Location
    Panama City, Panama
    Posts
    151

    Default Re: how to update lead via webform

    come on, still no reply on this... any ideas, questions, comments, inisight???

  4. #4
    scheinarts is offline Sugar Community Member
    Join Date
    Feb 2007
    Location
    Panama City, Panama
    Posts
    151

    Default Re: how to update lead via webform

    OK Im progressing with this.

    With this following code, you can create a lead. Simply set the variables in the input fields in your form...
    Code:
     <?php
     define('sugarEntry', TRUE);
     //Use the NuSOAP files
     require_once('nusoap/nusoap.php');
     
     $soapclient = new soapclient('http://www.example.com/sugar/soap.php?wsdl',true);
     
     $user_auth = array(
                     'user_auth' => array(
                           'user_name' => 'bob',
                           'password' => md5('mysecretpassword'),
                           'version' => '0.1'
                           ),
                     'application_name' => 'soapleadcapture');
    
    
    
     $result_array = $soapclient->call('login',$user_auth);
     
     $session_id =  $result_array['id'];
    
     $user_guid = $soapclient->call('get_user_id',$session_id);
      
     // Up until now, we have not introduced anything new
     // The following lines will use the set_entry SOAP call to add
     // a Lead from a mixture of POST variables and hard coded
     // values, then assign to the authenticated Sugar user...
     $set_entry_params = array(
                           'session' => $session_id,
                           'module_name' => 'Leads',
                           'name_value_list'=>array(
                               array('name'=>'first_name','value'=>$_POST['first_name']),
                               array('name'=>'last_name','value'=>$_POST['last_name']),
                               array('name'=>'status', 'value'=>'New'),
                               array('name'=>'phone_work', 'value'=>$_POST['phone']),
                               array('name'=>'phone_fax', 'value'=>$_POST['fax']),
                               array('name'=>'account_name','value'=>$_POST['companyname']),
                               array('name'=>'lead_source','value'=>'Web Site'),
                               array('name'=>'description','value'=>$_POST['prod_desc'])
                               array('name'=>'assigned_user_id', 'value'=>$user_guid)));
    
     $result = $soapclient->call('set_entry',$set_entry_params);
     
     // this redirects to a page specified in the previous page...
     header("Location:  " . $_POST['redirect']);
     
     ?>
    And if you add this array

    Code:
    array('name'=>'id','value'=>'65c64407-f02a-0b50-44e9-45dbbe49240d'),
    It will UPDATE the lead with that ID right from the web form



    I am going to detail the steps to achieve this automatic lead update process via webform (I think I have it figured out)
    1. Person fills out lead form on website and this form posts to addlead.php which is the code I just provide above.
    2. addlead.php will first create a lead, and inmediately call for the lead ID created in the database (DONT KNOW HOW TO DO THIS YET)
    3. addlead.php will inmediately email the person that filled out the lead form with a URL to the E-Brochure. The code for this is provided in my 2nd post on this thread.
    4. This URL will contain variables that will in turn pre-fill the form asking if he/she wants a Printed Brochure. Like this:
    Code:
    echo 'ebrochure.php?first_name=' . $_POST['first_name'] . '&last_name=' . $_POST['last_name']
    So then the actual URL in the email should look something like "ebrochure.php?first_name=John&last_name=Smith ". In this URL, there will also be the lead id pertaining to the lead previously created.
    5. On the form asking if he/she wants the Print Brochure, it will retrieve the predetermined fields like this:
    Code:
    <input type="text" name="first_name" id="first_name" value="<?php $_GET['first_name']; ?>" />
    . There will also be this hidden field in this form:
    Code:
    <input type="hidden" name="id" id="id" value="<?php $_GET['id']; ?>" />
    . This way all the information added will update the lead that was created by the person requesting the E-Brochure.
    6. The form contained in ebrochure.php (where E-Brochure is along with the Ask to Print Brochure FORM) will post to update_lead.php.
    7. update_lead.php will be a replica of addlead.php except it will have this array:
    Code:
    array('name'=>'id','value'=>$_POST['id']),
    These 7 steps SHOULD do what I requested on my first post.

    What I am trying to figure out now is how to get the lead id right after the lead was created. I need some help with this. Any body knows how to do this???
    Last edited by scheinarts; 2007-02-21 at 06:24 AM.

  5. #5
    gfa
    gfa is offline Sugar Community Member
    Join Date
    Jan 2007
    Posts
    23

    Default Re: how to update lead via webform

    i noticed that from the generated web lead form, after it submits to sugar and hits the return url you defined, sugar is posting variables back to the return url. i havent gotten to the point of tracing to find out what those variables are , maybe one of them is the lead id created? if you do the hard work be sure to post what variables you found are posted back.

  6. #6
    scheinarts is offline Sugar Community Member
    Join Date
    Feb 2007
    Location
    Panama City, Panama
    Posts
    151

    Default Re: how to update lead via webform

    I dont understand your question very well. Yes, in therory the lead id needs to be in the url so the next form updates this lead.

  7. #7
    scheinarts is offline Sugar Community Member
    Join Date
    Feb 2007
    Location
    Panama City, Panama
    Posts
    151

    Default Re: how to update lead via webform

    Where do I look for these variables?
    Last edited by scheinarts; 2007-02-21 at 05:06 PM.

  8. #8
    scheinarts is offline Sugar Community Member
    Join Date
    Feb 2007
    Location
    Panama City, Panama
    Posts
    151

    Default Re: how to update lead via webform

    I think it can be done using mysql queries.

    I am using this code...

    Code:
     mysql_connect("mysql.mysite.com", "sugaruser", "sugarpass") or die(mysql_error());
    mysql_select_db("sugar_dbname") or die(mysql_error()); 
    
    $data = mysql_query("SELECT id FROM leads WHERE email1 = 'anyname@anyemail.com';")
    or die(mysql_error());
    
    $info = mysql_fetch_array( $data );
    Then I added this code to see if I was getting the result i wanted and YES I am.

    Code:
    Print $info['id'];
    Print '<br>';
    Print $_POST['email1'];
    The question is... HOW DO I MAKE THE EMAIL ADDRESS A VARIABLE, SO THAT IT WILL CHANGE ON A PER LEAD CREATE BASIS.? Once this is done the lead ID that is printed will be for the lead just created. Were are assuming the all email address will be unique in the lead table.

  9. #9
    julian's Avatar
    julian is offline Sugar Team Member
    Join Date
    Sep 2004
    Posts
    1,639

    Default Re: how to update lead via webform

    Hello scheinarts,

    You can use variables within MySQL queries-- just make sure you escape the text properly, or people could perform SQL injection attacks.

    Here's an example of how to properly sanitize data for a query:

    PHP Code:
    mysql_connect("mysql.mysite.com""sugaruser""sugarpass") or die(mysql_error());
    mysql_select_db("sugar_dbname") or die(mysql_error()); 

    $email_to_search mysql_real_escape_string($_POST['email1']);

    $data mysql_query("SELECT id FROM leads WHERE email1 = '{$email_to_search}';")
    or die(
    mysql_error());

    $info mysql_fetch_array$data ); 
    Julian Ostrow
    Systems and Applications Engineer
    SugarCRM Inc.

  10. #10
    oktboy is offline Member
    Join Date
    Oct 2006
    Posts
    6

    Default Re: how to update lead via webform

    Is there a way to grab the record id after a soap call is made to create a lead into the DB? I know that soap will only return a true or false return type from the code below. And if I am creating several soap calls at a time making different lead entries then the last lead created will not be the one I would want to update? Do I modify the call() function to return an id? Thats my guess or is there something already built in to return that?


    $soapclient = new soapclient('http://address', true);

    $set_entry_params = array();

    $result = $soapclient->call('set_entry', $set_entry_params);


    Oscar

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 11
    Last Post: 2011-05-17, 02:14 AM
  2. From lead to order
    By george_bbch in forum Feature Requests
    Replies: 0
    Last Post: 2006-09-26, 02:02 PM
  3. Mass Update won't work!
    By rsantiago in forum Help
    Replies: 6
    Last Post: 2006-08-18, 02:54 AM
  4. [PHP] How to update a lead
    By groupeHEC in forum Developer Help
    Replies: 2
    Last Post: 2006-04-13, 11:56 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
  •