Lamplight API examples - creating referrals


A common scenario is the need to be able to accept referrals through a web-based form. The Lamplight API now allows you to do so, as part of the datain module.


If you would like to access our services, please enter your details here and we'll be in touch as soon as possible.

The code

To create a referral, we will use our Lamplight_Client to generate requests and handle responses, and the Lamplight_Record_Referral class to hold our data.

So firstly, we instantiate a new Lamplight_Record_Referral and set the properties that are available to us:

    $ref = new Lamplight_Record_Referral();


We can now pass this to our client to save it:


New in version 1.1 is the Lamplight_Datain_Response class. This provides a wrapper for the response received, making it easy to discover what happened. To get this object, we simply do:

     // $ret is an instance of Lamplight_Datain_Response
     $ret = $client->getDatainResponse();

     // and now use the convenience methods
     // success(), getErrorMessage() or getErrorCode()

     if ($resp->success()) {

         echo 'Thanks, your referral has been received OK';

     } else {

         echo 'Unfortunately there was a problem. 
'; echo $resp->getErrorMessage(); }

You can also use the Lamplight_Client methods to see more detail of the errors returned - see the documentation for more details.