Advertisement
redearth

Gravity Forms Vertical Response integration

Sep 27th, 2012
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.95 KB | None | 0 0
  1. add_action("gform_post_submission", "vr_subscribe", 10, 2);
  2. function vr_subscribe($entry, $form){
  3.  
  4.     // the gform field id numbers
  5.     $gf_field_id_optin      = '11.1'; // the gform field id for the subscribe opt-in checkbox
  6.     $gf_field_id_first_name = 9;
  7.     $gf_field_id_last_name  = 10;
  8.     $gf_field_id_email      = 2;
  9.     $gf_field_id_phone      = 3;
  10.     $gf_field_id_state      = 12;
  11.  
  12.     // Vertical Response
  13.     $vr_form_id             = '123xyx789eab';
  14.     $source                 = urlencode('The name of your form');
  15.     $site_admin_email       = 'test@test.com';
  16.  
  17.     if($entry[$gf_field_id_optin]){//opted-in
  18.  
  19.         //clean up needed?
  20.         $fname      = strip_tags($entry[$gf_field_id_first_name]);
  21.         $lname      = strip_tags($entry[$gf_field_id_last_name]);
  22.         $useremail  = strip_tags($entry[$gf_field_id_email]);
  23.         $phone      = strip_tags($entry[$gf_field_id_phone]);
  24.         $state      = strip_tags($entry[$gf_field_id_state]);
  25.  
  26.         $language   = false;
  27.         // if using the WPML plugin, pick up the language from the URL
  28.         if(stripos($entry['source_url'],'/es/')!==false){
  29.             $language = 'Spanish';
  30.         } elseif(stripos($entry['source_url'],'/zh-hant/')!==false){
  31.             $language = 'Chinese';
  32.         }
  33.         $url = "http://oi.vresp.com?fid=".$vr_form_id;
  34.  
  35.         $postFields = "first_name=".$fname;
  36.         $postFields .= "&last_name=".$lname;
  37.         $postFields .= "&email_address=".$useremail;
  38.         $postFields .= "&home_phone=".$phone;
  39.         $postFields .= "&state=".$state;
  40.         $postFields .= "&language=".$language;
  41.         $postFields .= "&source=".$source;
  42.  
  43.         //Start cURL
  44.         $ch = curl_init();
  45.         curl_setopt($ch, CURLOPT_URL, $url);
  46.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  47.         curl_setopt($ch, CURLOPT_POST, true);
  48.         curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
  49.         //If cURL is successful
  50.         if ($response = curl_exec($ch)) {
  51.             //mail($site_admin_email,"test successful",$url."\n".$postFields,"from:".$site_admin_email);
  52.         } else {
  53.             mail($site_admin_email,"There was an error posting to Vertical Response","Error:\n".$postFields,"from:".$site_admin_email);
  54.         }
  55.         curl_close($ch);
  56.  
  57.     } else {//didn't subscribe
  58.         //no need to email site admin...
  59.     }
  60.     /* other available gform standard field data:
  61.         id => 4
  62.         form_id => 1
  63.         date_created => 2012-09-27 14:01:53
  64.         is_starred => 0
  65.         is_read => 0
  66.         ip => xx.xx.xx.xx
  67.         source_url => http://...
  68.         post_id =>
  69.         currency => USD
  70.         payment_status =>
  71.         payment_date =>
  72.         transaction_id =>
  73.         payment_amount =>
  74.         is_fulfilled =>
  75.         created_by => 1
  76.         transaction_type =>
  77.         user_agent => Mozilla/5.0 (Windows NT 6.0; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1
  78.         status => active
  79.     */
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement