Skip to content

Instantly share code, notes, and snippets.

@ksnider
Created January 28, 2014 05:20
Show Gist options
  • Select an option

  • Save ksnider/8662649 to your computer and use it in GitHub Desktop.

Select an option

Save ksnider/8662649 to your computer and use it in GitHub Desktop.
<?php
/*
++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++
++ ++
++ Get GF data from query ++
++ string and write it to IS ++
++ ++
++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++
*/
//formId={form_id}&entryId={entry_id}&email={Email:5}&fname={Name (First):1.3}&lname={Name (Last):1.6}
// Get quiz values from query string
/*
$formId = $_GET['formId'];
$entryId = $_GET['entryId'];
$email = $_GET['email'];
$fname = $_GET['fname'];
$lname = $_GET['lname'];
require("isdk.php");
$app = new iSDK;
if ($app->cfgCon("sandbox")) {
// Current date in Infusionsoft-friendly format
$currentDate = date_format(date_create(), 'Ymd H:i:s');
echo "You connected at $currentDate <br/>";
$update = array('FirstName' => $fname, 'LastName' => $lname, 'Email' => $email, 'Company' => 'Kim's Company');
$app->addWithDupCheck($update, 'Email');
} else {
echo "Not Connected...";
}
*/
/*
++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++
++ ++
++ Get GF data from db ++
++ and write it to IS ++
++ ++
++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++
*/
// Confirmation is passing FormID, LeadID and Email Address
// in a query string
$formId = $_GET['formId'];
$formId = $_GET['formId'];
$email = $_GET['email'];
// This is the GF table that contains form submissions
// Your db name will be different
$table = "your_wp_db_name.wp1_rg_lead_detail";
// Hard coded-test data
// $formId = 6;
// $leadId = 38;
// $email = 'nessa@kimsnider.com';
try {
// Instantiate new db object and connection to WP database
$conn = new PDO("mysql:host=localhost;dbname=your_wp_db_name;charset=utf8;", "your_db_user_name", "your_db_pwd");
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT COUNT(*) FROM $table WHERE form_id = $formId AND lead_id = $leadId";
if ($res = $conn->query($sql)) { // Check the connection exists
/* Check the number of rows that match the SELECT statement */
if ($res->fetchColumn() > 0) {
// Use prepared statements and parameterized queries to prevent SQL injection
// See excellent post in Stack Overflow for details
// http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1
/*
form_id is the column name in your db
:formid is the named placeholder (referred to again in line 107)
$formId is the value passed from the form
*/
$sql = "SELECT * FROM $table WHERE form_id = :formid AND lead_id = :leadid";
$stmt = $conn->prepare($sql);
// These exchange the value of the variable for the placeholder in the query
$stmt->execute(array('formid' => $formId, 'leadid' => $leadId));
$result = $stmt->fetchAll();
// If you run to this point, you will get an output of the data from your
// form submission so you can see the structure of the data
echo "<pre>";
print_r($result);
echo "</pre>";
/*
// This next section of code is not specific to the form we filled out in
// the webinar. It is an example from one of my forms about how you move the
// information to Infusionsoft. I have included it so you have a
// complete example
// Connect to Infusionsoft
require_once('isdk.php');
$app = new iSDK;
if ($app->cfgCon("sandbox")) {
// Add the contact to Infusionsoft with Dup Check
$contactId = $app->addWithDupCheck(array('Email' => $email), 'Email');
//Grab custom field values and apply tags for interests
foreach ($result as $row) {
$fieldnum = $row['field_number'];
switch ($fieldnum) {
case 5:
$answer1 = $row['value'];
break;
case 6:
$answer2 = $row['value'];
break;
case 4.2: // Polo Club Owner
$tag = $app->grpAssign($contactId, 2145);
break;
case 4.3: // Polo Player - Male set gender
$tag = $app->grpAssign($contactId, 2147);
break;
case 4.4: // Polo Player - Female
$tag = $app->grpAssign($contactId, 2149);
break;
case 4.5: // Polo Player - Junior
$tag = $app->grpAssign($contactId, 2151);
break;
case 4.6: // Active Social Member
$tag = $app->grpAssign($contactId, 2153);
break;
case 4.7: // Polo Instructor
$tag = $app->grpAssign($contactId, 2155);
break;
case 4.8: // Support Jr Polo
$tag = $app->grpAssign($contactId, 2157);
break;
case 4.9: // Polo Club Mgr
$tag = $app->grpAssign($contactId, 2159);
break;
case 4.11: // Polo Ofc Staff
$tag = $app->grpAssign($contactId, 2161);
break;
case 4.13: // YPO
$tag = $app->grpAssign($contactId, 2163);
break;
case 9: // Facebook
$fbook = $row['value'];
break;
default:
break;
}
}
// Update custom fields with form values
$update = array('_Answer1' => $answer1,
'_Answer2' => $answer2,
'_DoYouFacebook' => $fbook);
$app->dsUpdate("Contact", $contactId, $update);
// Set the Completed Form tag
$tag = $app->grpAssign($contactId, 2143);
// redirect to Thank You Page
header('Location: http://uspolo.org/why-thanks/');
} else {
echo "Not Connected...";
}
*/
} /* No rows matched -- do something else */
else {
print "No rows matched the query.";
}
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment