Advertisement
chrishajer

Include conditional information in notification

Jul 30th, 2012
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // http://www.gravityhelp.com/forums/topic/modufy-user-notification-email-based-on-dropdown-selection#post-66948
  2. // change the 110 here to your form ID
  3. add_action('gform_pre_submission_filter_110', 'add_provider_details');
  4. function add_provider_details($form) {
  5.  
  6.         // define three providers
  7.         $providers = array(
  8.                 0 => array(
  9.                         'company' => 'Alcohol Monitoring Systems Corporate',
  10.                         'first'   => 'Murray',
  11.                         'last'    => 'Brooks',
  12.                         'phone'   => '303-917-5405',
  13.                         'email'   => 'mbrooks@alcoholmonitoring.com'
  14.                 ),
  15.                 1 => array(
  16.                         'company' => 'Reliant Monitoring Services',
  17.                         'first'   => 'Nate',
  18.                         'last'    => 'Gay',
  19.                         'phone'   => '919-754-9422',
  20.                         'email'   => 'nategay@reliantmanagement.com'
  21.                 ),
  22.                 2 => array(
  23.                         'company' => 'Tarheel Monitoring West',
  24.                         'first'   => 'David',
  25.                         'last'    => 'Collins',
  26.                         'phone'   => '704-253-1054',
  27.                         'email'   => 'scramxwestnc@gmail.com'
  28.                 ),
  29.         );
  30.  
  31.         // define the provider ID for each county in the form
  32.         $counties = array(
  33.                 'Alamance' => 0,
  34.                 'Alexander' => 0,
  35.                 'Alleghany' => 0,
  36.                 'Anson' => 1,
  37.                 'Ashe' => 0,
  38.                 'Avery' => 0,
  39.                 'Beaufort' => 1,
  40.                 'Bertie' => 1,
  41.                 'Bladen' => 0,
  42.                 'Brunswick' => 0,
  43.                 'Buncombe' => 0,
  44.                 'Burke' => 2,
  45.                 'Cabarrus' => 0,
  46.                 'Caldwell' => 2,
  47.                 'Camden' => 0,
  48.                 'Carteret' => 1,
  49.                 'Caswell' => 1,
  50.                 'Catawba' => 2,
  51.                 'Chatham' => 1,
  52.                 'Cherokee' => 0,
  53.                 'Chowan' => 0,
  54.                 'Clay' => 0,
  55.                 'Cleveland' => 0,
  56.                 'Columbus' => 0,
  57.                 'Craven' => 1,
  58.                 'Cumberland' => 1,
  59.                 'Currituck' => 0,
  60.                 'Dare' => 0,
  61.                 'Davidson' => 0,
  62.                 'Davie' => 0,
  63.                 'Duplin' => 1,
  64.                 'Durham' => 0,
  65.                 'Edgecombe' => 1,
  66.                 'Forsyth' => 0,
  67.                 'Franklin' => 1,
  68.                 'Gaston' => 0,
  69.                 'Gates' => 0,
  70.                 'Graham' => 0,
  71.                 'Granville' => 1,
  72.                 'Greene' => 1,
  73.                 'Guilford' => 0,
  74.                 'Halifax' => 1,
  75.                 'Harnett' => 1,
  76.                 'Haywood' => 0,
  77.                 'Henderson' => 0,
  78.                 'Hertford' => 1,
  79.                 'Hoke' => 1,
  80.                 'Hyde' => 1,
  81.                 'Iredell' => 0,
  82.                 'Jackson' => 0,
  83.                 'Johnston' => 1,
  84.                 'Jones' => 1,
  85.                 'Lee' => 1,
  86.                 'Lenoir' => 1,
  87.                 'Lincoln' => 0,
  88.                 'McDowell' => 0,
  89.                 'Macon' => 0,
  90.                 'Madison' => 0,
  91.                 'Martin' => 1,
  92.                 'Mecklenburg' => 0,
  93.                 'Mitchell' => 0,
  94.                 'Montgomery' => 1,
  95.                 'Moore' => 1,
  96.                 'Nash' => 1,
  97.                 'NewHanover' => 0,
  98.                 'Northampton' => 1,
  99.                 'Onslow' => 1,
  100.                 'Orange' => 1,
  101.                 'Pamlico' => 1,
  102.                 'Pasquotank' => 0,
  103.                 'Pender' => 0,
  104.                 'Perquimans' => 0,
  105.                 'Person' => 1,
  106.                 'Pitt' => 1,
  107.                 'Polk' => 0,
  108.                 'Randolph' => 1,
  109.                 'Richmond' => 1,
  110.                 'Robeson' => 1,
  111.                 'Rockingham' => 0,
  112.                 'Rowan' => 2,
  113.                 'Rutherford' => 0,
  114.                 'Sampson' => 1,
  115.                 'Scotland' => 1,
  116.                 'Stanly' => 1,
  117.                 'Stokes' => 0,
  118.                 'Surry' => 0,
  119.                 'Swain' => 0,
  120.                 'Transylvania' => 0,
  121.                 'Tyrrell' => 1,
  122.                 'Union' => 1,
  123.                 'Vance' => 1,
  124.                 'Wake' => 0,
  125.                 'Warren' => 1,
  126.                 'Washington' => 1,
  127.                 'Watauga' => 0,
  128.                 'Wayne' => 1,
  129.                 'Wilkes' => 0,
  130.                 'Wilson' => 1,
  131.                 'Yadkin' => 0,
  132.                 'Yancey' => 0
  133.         );
  134.  
  135.         // define notification parts here
  136.         $part_one   = "<table id='backgroundTable' width='100%' border='0' cellspacing='0' cellpadding='0'><tbody><tr><td style='height: 100% !important; margin: 0 !important; padding: 0 !important; width: 100% !important;' align='center' valign='top'><!-- Body --><table id='templateBody' width='100%' border='0' cellspacing='0' cellpadding='20'><tbody><tr><td align='center' valign='top'><table width='560' border='0' cellspacing='0' cellpadding='0'><tbody><tr><td class='bodyContent' style='padding-bottom: 40px;' valign='top'><img id='headerImage campaign-icon' style='max-width: 560px;'src='http://alcoholmonitoring.com/site/designs/shared/images/logo-scramx.png' alt='' /><h1>SCRAMx Offender Referral Confirmation</h1><p>{Referring Officer Name (First):8.3} {Referring Officer Name (Last):8.6},</p><p>Success! Your referral information was submitted and has been receieved by the authorized SCRAMx service provider for <strong>{Referring County:2} County</strong>:</p>";
  137.         $part_three = "<h2>Offender Information</h2><p>{Offender Name (First):14.3} {Offender Name (Last):14.6}<br /><strong>OPUS Number:</strong> {OPUS Number:15}</p></td></tr></tbody></table></td></tr></tbody></table><!--  Body --></td></tr></tbody></table>";
  138.  
  139.         // read the county from the form submission.  It's in field #2 currently
  140.         $county     = rgpost('input_2');
  141.  
  142.         // determine the county ID from the country string that was submitted
  143.         $countyID   = $counties[$county];
  144.  
  145.         // retrieve provider information based on the county ID
  146.         $providerCompany = $providers[$countyID]['company'];
  147.         $providerFirst   = $providers[$countyID]['first'];
  148.         $providerLast    = $providers[$countyID]['last'];
  149.         $providerPhone   = $providers[$countyID]['phone'];
  150.         $providerEmail   = $providers[$countyID]['email'];
  151.  
  152.         // concatenat all the provider information
  153.         $providerInfo = "<h2>Provider Information</h2><p>Company Name: $providerCompany<br />Contact Name: $providerFirst $providerLast<br />Contact Phone: $providerPhone<br />Referral Email: <a href='mailto:$providerEmail' title='send an email'>$providerEmail</a><br /></p>";
  154.  
  155.         // concatenat all three parts of the notification
  156.         $form['autoResponder']['message'] = $part_one . $providerInfo . $part_three;
  157.  
  158.         // return the $form object which will contain the user notification
  159.         return $form;
  160. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement