chrishajer

Add BCC notifications based on check boxes

Oct 22nd, 2011
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // http://www.gravityhelp.com/forums/topic/help-with-conditional-routing
  2. // change the 53 here to your form ID
  3. add_filter('gform_pre_submission_filter_53', 'add_bcc');
  4. function add_bcc($form){
  5.  
  6.     // the array indexes here are the values of the input select boxes.  View source of the form to see the actual IDs
  7.     $addresses = array(
  8.         1 => 'store1a@example.com,store1b@example.com',
  9.         2 => 'store2a@example.com,store2b@example.com',
  10.         3 => 'store3a@example.com,store3b@example.com',
  11.         4 => 'store4a@example.com,store4b@example.com',
  12.         5 => 'store5a@example.com,store5b@example.com',
  13.         6 => 'store6a@example.com,store6b@example.com',
  14.         7 => 'store7a@example.com,store7b@example.com',
  15.         8 => 'store8a@example.com,store8b@example.com',
  16.         9 => 'store9a@example.com,store9b@example.com',
  17.         11 => 'store10a@example.com,store10b@example.com',
  18.         12 => 'store11a@example.com,store11b@example.com',
  19.         13 => 'store12a@example.com,store12b@example.com',
  20.         14 => 'store13a@example.com,store13b@example.com',
  21.         15 => 'store14a@example.com,store14b@example.com',
  22.         16 => 'store15a@example.com,store15b@example.com',
  23.         17 => 'store16a@example.com,store16b@example.com',
  24.         18 => 'store17a@example.com,store17b@example.com',
  25.         19 => 'store18a@example.com,store18b@example.com',
  26.         21 => 'store19a@example.com,store19b@example.com',
  27.         22 => 'store20a@example.com,store20b@example.com',
  28.         22 => 'store21a@example.com,store21b@example.com',
  29.         24 => 'store22a@example.com,store22b@example.com',
  30.         24 => 'store23a@example.com,store23b@example.com',
  31.         25 => 'store24a@example.com,store24b@example.com',
  32.         26 => 'store25a@example.com,store25b@example.com',
  33.         27 => 'store26a@example.com,store26b@example.com',
  34.         28 => 'store27a@example.com,store27b@example.com',
  35.         29 => 'store28a@example.com,store28b@example.com',
  36.         31 => 'store29a@example.com,store29b@example.com',
  37.         32 => 'store30a@example.com,store30b@example.com'
  38.     );
  39.  
  40.     // my form uses input_1 for the select box.  Your form may be different.  Change it here is necessary
  41.     $input_prefix = 'input_1_';
  42.  
  43.     // clear out any BCC notifications from the form builder
  44.     $bcc = '';
  45.  
  46.     // loop through 30 fields to see if we need to send more notifications
  47.     for ($i=1; $i<=30; $i++) {
  48.  
  49.         // be careful: Gravity Forms avoids numbering inputs with numbers ending in zero
  50.         $input_field = $input_prefix . $i;
  51.  
  52.         // Check the form submission for the select box. If there is a value in $input_field, then add the addresses for that selection to the bcc list
  53.         // rgpost is a safe way of accessing the $_POST values
  54.         if (rgpost($input_field)) {
  55.             $bcc .= $addresses[$i] . ','; // we'll strip off this last comma later
  56.         }
  57.     }
  58.  
  59.     // remove the trailing comma is there is one
  60.     $form['notification']['bcc'] = rtrim($bcc, ',');
  61.  
  62.     // return the modified form object
  63.     return $form;
  64. }
  65.  
RAW Paste Data