1) Open your favorite text editing program
2) Copy and paste the following PHP code into the blank text editor file:
NOTE: Lines beginning with “//” denote comments explaining what the subsequent chunk of code does. They also sometimes point out things you can change or customize in the code. Reading through them will help you get a judo grip on the code and its nuances and let you cater the code to your needs.
<?php echo "Hello World! <br/><br/>"; // Connect to Infusionsoft require_once("isdk.php"); $app = new iSDK; if ($app->cfgCon("sandbox")) { // Current date in Infusionsoft-friendly format $currentDate = date_format(date_create(), 'YmdTH:i:s'); echo "You connected at $currentDate <br/><br/>"; // Recipe starts here // Assign POST variables using ternary operator instead of IF statement // If your POST is being sent from somewhere other than Infusionsoft, // you may need to modify the name in $_POST[] to match form field name or key if ($_POST['Id']) { $conID = $_POST['Id']; } else { $conID = ($_POST['contactId']) ? $_POST['contactId'] : ''; } $fname = ($_POST['FirstName']) ? $_POST['FirstName'] : ''; // Make the value all lower case and then capitalize first letter $capname = ucwords(strtolower($fname)); // Write the result back to First Name field in Infusionsoft $conDat = array('FirstName' => $capname); $conID = $app->updateCon($conID, $conDat); } else { echo "Not Connected..."; }
3) Now that you’ve got the code in your text editor, it’s time to edit it to suit your needs/wants/whimsies. Most of the script should work just fine as-is, but it does need a few customizations here and there. First, let’s look at these lines:
if ($_POST['Id']) { $conID = $_POST['Id']; } else { $conID = ($_POST['contactId']) ? $_POST['contactId'] : ''; }
These lines are using the Ternary Operator as a shorthand for a traditional nested If/Else Statement to get the Contact Id, if it exists, from the $_POST variable. Because we aren’t sure where the $_POST variable is coming from, we need to allow for all cases. If it’s coming from an Infusionsoft Action Set, “Id” is going to get assigned to $conID. If it’s coming from the Campaign Builder, “contactId” is going to get assigned to $conID. And if it’s coming from an external source like a Gravity Form on your website, there may be no Contact Id at all, in which case we need to tell $conID this field should be empty.
The only reason you may need to change this code is if you decide to change the default (“contactId”) in Campaign Builder to something else. In that case, you’ll need to replace “contactId” with your new variable name. Otherwise, you’re good to go.
4) You probably will need to change line 30 if you’re using an external form or if you change the Infusionsoft default (“FirstName”) in Campaign Builder. Remember, variables are case sensitive, so “firstname” is NOT the same as “FirstName”. Yours may be “First”, “Name” or any variation. Make sure your variable name matches here.
$fname = ($_POST['FirstName']) ? $_POST['FirstName'] : '';
In line 38 there’s another instance of the $_POST variable that you may need to change.
$conDat = array('FirstName' => $capname);
Other than these changes, the rest of the code should work right out of the box. Remember, your clients are probably just as sloppy getting their last names in their contact records too, so have fun getting those looking good with a little alteration to this code!