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 //Connects to the Infusionsoft API. This is a standard way to start any script that uses the Infusionsoft API. No tweaks necessary here! require("isdk.php"); $app = new iSDK; $app->cfgCon("connectionName"); //The variable (dateFieldName) stores the name of the custom Infusionsoft field where the date will be posted (NameOfYourDateField in this case). // Custom fields in Infusionsoft always have an underscore before their name when being referenced by a script. $dateFieldName = '_NameOfYourDateField'; //Get post data for Contact ID. $contactId = $_POST['Id']; //Stores today's date in YearMonthDate format. $currentDate = date("YmdTH:i:s"); //Grabs the data from Infusionsoft for your custom field. $returnFields = array($dateFieldName); //dsLoad is an Infusionsoft API method that grabs data from the specified field in Infusionsoft. $contacts = $app->dsLoad("Contact", $contactId, $returnFields); //If NameOfYourDateField is currently empty/unset, then set it to today's date. If it's already set, add one year to the date if (isset ($contacts['_NameOfYourDateField']) == FALSE) { $conDat = array($dateFieldName => $currentDate); } else { $classOf = strtotime($contacts['_NameOfYourDateField']); $yrPlusOne = date("YmdTH:i:s", strtotime('+1 year', $classOf)); $conDat = array($dateFieldName => $yrPlusOne); } //Another API method that updates a given contact with the data in the second variable passed. $conID = $app->updateCon($contactId, $conDat); ?>
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 this line:
$dateFieldName = '_NameOfYourDateField';
As the comment says, dateFieldName is a variable that will represent the custom field where you want to put the date in Infusionsoft. You need to change ‘_NameOfYourDateField’ to ‘_WhateverYourCustomFieldIsActuallyCalled’. For instance, if you wanted to put the date in a custom Infusionsoft field called MyCustomDate, you would put ‘_MyCustomDate’. You also need to change this anywhere else the code references ‘_NameOfYourDateField’, so in your text editor use the Find-and-Replace function to change all instances of ‘_NameOfYourDateField’ to ‘_MyCustomDate’ or whatever you named your field.
4) Jump down to the line
$currentDate = date("YmdTH:i:s");
Right now, this bit of PHP will store the current date in a variable aptly named currentDate in the format YYYYMMDD followed by the time-zone abbreviation followed by the time in 24-hour/military time format. So if it was 3:19 PM on September 20th, 2013 in Eastern Standard Time, the script would format the date as 20130920EST15:19:00. This is handled in the code by the part in quotes that looks like a cat ran across the keyboard (“YmdTH:i:s”) and you can change it around however you want. This is how it presently breaks down:
Y – The 4-digit year
m – The 2-digit month with leading zeroes (
d – The 2-digit day with leading zeroes.
T – Time-zone abbreviation
H – The hour using a 24-hour clock
i – Minutes
s – seconds
You could re-arrange it to (“m d Y H:i:s T”) and the script would then format the date as 09 20 2013 15:19:00 EST. You can also change how the date appears by switching the letters you use. For instance, changing the ‘m’ to ‘F’ would make the month in the date appear as “September” instead of “09.” For a full list of all possible formatting options, refer to the PHP manual here : http://php.net/manual/en/function.date.php.
5) The last line you might want to tweak is:
$yrPlusOne = date("YmdTH:i:s", strtotime('+1 year', $classOf));
Currently, this script will add one year to the contact’s custom date field every time you run this script. So if you initially set the contact’s date to 09/20/2013 (formatted however you chose, obviously), the next time you run the script that date will be updated to 09/20/2014. You can change ‘+1 year’ to ‘+1 month’ or ‘+1 day’ depending on what increment you want. Go ahead, try it! It’s like magic. Internet magic.
And that’s it! Congratulations, you have a custom date in a custom field that goes up by a custom increment every time you run this script. It’s so custom that “custom” probably doesn’t sound like a real word to you anymore!