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???
Bookmarks