This is the HTML for a sample form you can use for testing.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Web Form Test</title> </head> <body> <!-- this tells the browser where and how to send the data from the form --> <form action='cb_add_contact.php' method='post' enctype="multipart/form-data"> <!-- the script puts this data into Infusionsoft --> First Name : <input type='text' name='FirstName'><br /> Last Name : <input type='text' name='LastName'><br /> Email : <input type='text' name='Email' ><br /> <input type='submit' value='Test'> </form> </body> </html>
This is the PHP for the script being called by the test form.
<?php echo "Hello World! <br/>"; // Connect to Infusionsoft require_once("isdk.php"); $app = new iSDK; if ($app->cfgCon("connectionName")) { // Current date in Infusionsoft-friendly format $currentDate = date_format(date_create(), 'YmdTH:i:s'); echo "You connected at $currentDate <br/>"; // Recipe begins here /* These are test values - make sure they are deleted or commented out when testing is complete */ //$fname = 'John'; //$lname = 'Kennedy'; //$email = 'jfk@whitehouse.gov'; // Check to see if the request method is POST or GET if ($_SERVER[REQUEST_METHOD] == 'POST') { if ($_POST['FirstName']) { $fname = $_POST['FirstName']; // These must match the name of the field in your form } else { $fname = ''; } if ($_POST['LastName']) { $lname = $_POST['LastName']; // including proper capitalization } else { $lname = ''; } if ($_POST['Email']) { $email = $_POST['Email']; } else { $email = ''; } } else { // We are going to assume it is a GET coming from an Action // This is a short hand for IF ELSE called a ternary operator $_GET['FirstName'] ? $fname = $_GET['FirstName'] : $fname = ''; $_GET['LastName'] ? $lname = $_GET['LastName'] : $lname = ''; $_GET['Email'] ? $email = $_GET['Email'] : $email = ''; // This does the same thing as the code in the IF // but notice how much cleaner and easier to read it is } // Update contact record using AddWithDupCheck method $data = array('FirstName' => $fname, // The key on the left must exact match table field names 'LastName' => $lname, // The value on the right can be anything as long as type matches field 'Email' => $email); // e.g you cannot put a string in date field $update = $app->addWithDupCheck($data, 'Email'); // This is the API call which checks for duplicates using Email and Name echo $update; // If successful, this will return the contactId of the contact added or updated } else { echo "Not Connected..."; } ?>