Advertisement
chrishajer

Add BCC notifications based on check boxes

Oct 22nd, 2011
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.79 KB | None | 0 0
  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.     );
  9.  
  10.     // my form uses input_1 for the select box.  Your form may be different.  Change it here is necessary
  11.     $input_prefix = 'input_1_';
  12.  
  13.     // clear out any BCC notifications from the form builder
  14.     $bcc = '';
  15.  
  16.     // loop through 30 fields to see if we need to send more notifications
  17.     for ($i=1; $i<=30; $i++) {
  18.  
  19.         // be careful: Gravity Forms avoids numbering inputs with numbers ending in zero
  20.         $input_field = $input_prefix . $i;
  21.  
  22.         // 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
  23.         // rgpost is a safe way of accessing the $_POST values
  24.         if (rgpost($input_field)) {
  25.             $bcc .= $addresses[$i] . ','; // we'll strip off this last comma later
  26.         }
  27.     }
  28.  
  29.     // remove the trailing comma is there is one
  30.     $form['notification']['bcc'] = rtrim($bcc, ',');
  31.  
  32.     // return the modified form object
  33.     return $form;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement