Advertisement
chrishajer

Create notification of just submitted fields, no blanks

Oct 14th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2. // create custom notification which includes only submitted fields
  3. // change the 487 here to your form ID
  4. add_filter('gform_notification_487', 'custom_format', 10, 3);
  5. function custom_format($notification, $form, $entry) {
  6.         // be sure this is the name of your notification, change it if not
  7.     if($notification['name'] == 'Admin Notification'){
  8.         $notification['message_format'] = 'html';
  9.         $notification['message'] = '<table width="600" border="0">';
  10.         foreach ($entry as $key => $value) {
  11.             // only output form fields, not entry meta
  12.             if (is_numeric($key)) {
  13.                 // trim whitespace from $value
  14.                 $value = trim($value);
  15.                 // if the value is not empty for this field, add it to the notification
  16.                 if(!empty($value)) {
  17.                     // get the field information from the form
  18.                     $field = RGFormsModel::get_field($form, $key);
  19.                     // add a line to the notification
  20.                     $notification['message'] .= "<tr><td>" . $field['label'] ."</td><td>$value</td></tr>";
  21.                 }
  22.             }
  23.         }
  24.         $notification['message'] .= '</table>';
  25.     }
  26.     // return the notification either way
  27.     return $notification;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement