Hi everyone, I'm working on some custom PHP code that needs to capture newly added members' data and pass some of it to Salesforce. I have the code I need to properly communicate with Salesforce, but I could use some guidance on how to capture the firstname, lastname, etc. from the Signup form. I have the API plugin installed, and I've read most of the API documentation. Would sending the new user to a custom Thank You page from the signup form, and processing the variables and Salesforce code there be the easiest way to accomplish this data transfer? Toolie
Toolie, The simplest way will be to use hooks. For example if you need to execute some code after completed paymet you can use this code in site.php: PHP: <?php Am_Di::getInstance()->hook->add(Am_Event::PAYMENT_AFTER_INSERT, 'onPaymentAfterInsert');function onPaymentAfterInsert(Am_Event_PaymentAfterInsert $event){ $payment = $event->getPayment(); $user = $event->getUser(); // Your code here}?>
Awesome. I seem to remember that there was a way to connect, but I didn't remember what it was called or where to find the documentation. I believe I found it here: http://www.amember.com/docs/API/HookManager If I get stuck, I'll post more questions. Thanks Alexander! Toolie
Hi Alexander, the code above expects that a payment will have occurred, and we're using Amember only to control access to free resources. Here is the sequence of events: User clicks on link to protected resources User must sign in or sign up for free access (lifetime) User completes the form, clicks "I accept" on a terms of use agreement User is redirected to a custom Thank You Page I need to capture this user information First name Last name Title Company Email Phone when they first sign up, but not on subsequent signups for access to other areas of the site. The hook that seems to be applicable to Free Trials is this: Code: /** Called when an invoice becomes active_recurring or paid, or free trial is started * * {@link Invoice Invoice} * : invoice */ const INVOICE_STARTED = 'invoiceStarted'; How do I get from that trigger to retrieving the above fields for the person who just added themselves? Toolie
Yes you right ion this situation you should use INVOICE_STARTED hook: PHP: Am_Di::getInstance()->hook->add(Am_Event::INVOICE_STARTED, 'onInvoiceStarted');function onInvoiceStarted(Am_Event $event){ $invoice = $event->getInvoice(); $user = $invoice->getUser(); // Then you can get all above info from User record for example: // $user->email; // $user->name_f; // etc... // You can get custom fields the same way: // SQL field: // $user->fieldname; // Common field: // $user->data()->get('fieldname');}
Got it. I've incorporated the code and I'm trying to run a test to see that the trigger is happening by generating an email to myself with the field data. I'd like to first generate an email as part of the trigger for testing purposes, rather than peppering the Sales department's Salesforce account with a bunch of dummy records. This site is on an Amazon Web Services (AWS) EC2 instance, and I've configured Amember to use the SMTP transport to their Simple Email Service (SES) using as is required by AWS. Is there an easy way to utilize the built-in Amember email module to send these tests emails to myself? I see some mailing code in the following post, but that's for generating an unsubscribe link. http://www.amember.com/forum/thread...e-s-xxxxxx-unsubscribe-code.16568/#post-64290 Given the following: Code: $firstname = $user->name_f; $lastname = $user->name_l; $email = $user->email; $company = $user->company; $title = $user->title; $phone = $user->phone; How would I construct an email to myself as Admin that contains the field data, as proof that the trigger is working? Toolie
Here is how you can send mail from your code: PHP: $mail = new Am_Mail(); $mail->addTo('email@address.com'); $mail->setSubject('Subject'); $mail->setBodyText('Body of the message'); $mail->send(); Message will be sent using default transport configured in amember CP -> Setup -> Email
Awesome, that worked beautifully. Now one, more request from the Sales Department: they want to have me include what I have deduced to be the 'item_title' from the $invoice variable. It looks like the information would be somewhere in the array, but I am not clear how to navigate the JSON to get to it. In this situation, we sell only one product per form, but I suspect I'm still going to have to address the array. I looked around to find an example of how to retrieve it, but came up empty. Can you suggest how to proceed?
I went trolling through the Amember files themselves and found the one line that made it all work: $invoice = $event->getInvoice(); $selected = $invoice->getItem(0)->item_title; This pulls out just the first item (in our case there's only ONE item per invoice) and provides the title to me.
For everyone who has been following this thread, here's my complete solution: PHP: Am_Di::getInstance()->hook->add(Am_Event::INVOICE_STARTED, 'onInvoiceStarted');function onInvoiceStarted(Am_Event $event){ $invoice = $event->getInvoice(); $selected = $invoice->getItem(0)->item_title; // that's item zero in the array $user = $invoice->getUser(); $firstname = $user->name_f; $lastname = $user->name_l; $email = $user->email; $company = $user->data()->get('company'); // company is a custom field $title = $user->data()->get('title'); // title is a custom field $phone = $user->phone; $oid = "your_salesforce_id_here"; $data = array( "oid" => $oid, "first_name" => $firstname, "last_name" => $lastname, "title" => $title, "company" =>$company, "email" => $email, "phone" => $phone, "lead_source" => "your_lead_source_here", "devproductdownload__c" => $selected // This is a custom field I added in Salesforce );/********************************************* Use cURL to post to Salesforce web to lead********************************************/ // Create a new cURL resource $ch = curl_init(); // Set Options // Point to the Salesforce Web to Lead page curl_setopt($ch, CURLOPT_URL, "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8"); // Set the method to POST curl_setopt($ch, CURLOPT_POST, 1); // Pass POST data curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_exec($ch); // Post to Salesforce curl_close($ch); // close cURL resource /********************************************* Send email with values to Amember Admin********************************************/ $mail = new Am_Mail(); $mail->addTo('me@email.com'); $mail->setSubject('User data collected for Salesforce'); $mail->setBodyText('The following user data was acquired.'."\r\n" . "Name: ". $firstname." ".$lastname."\r\n" . "Title: ". $title."\r\n" . "Company: ". $company."\r\n" . "Phone: ". $phone."\r\n" . "Email: ". $email."\r\n" . "Product Selected: ". $selected); $mail->send();}?>