Advertisement
chrishajer

Notification which is conditional on yes radio choices

Dec 10th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2. // http://www.gravityhelp.com/forums/topic/automatic-notification-if-multiple-radio-buttons-selected#post-93500
  3. // change the 228 here to your form ID
  4. add_filter('gform_pre_submission_filter_228', 'yes_or_no_notification');
  5. function yes_or_no_notification($form){
  6.  
  7.         // initialize value to prevent 'undefined' notice
  8.         $yes = 0;
  9.  
  10.         // an array of all the radio button fields to be included in our yes/no check
  11.         $questions = array(5,6,8,9,10,11,12,13,14,15,16,17,18,19,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,46,47);
  12.  
  13.         // loop through all form fields looking for Yes answers
  14.         foreach ($questions as $field) {
  15.                 if (rgpost("input_{$field}") == 'Yes'){
  16.                         // we're actually going to count the yes answers
  17.                         $yes++;
  18.                 }
  19.         }
  20.  
  21.         // set the admin notification message based on the number of yes responses
  22.         if($yes == 0) {
  23.                 $form['notification']['message'] = "<p>This is the admin notification if all questions were answered NO.";
  24.         }
  25.         else {
  26.                 $form['notification']['message'] = "<p>This is the admin notification if any question was answered YES.";
  27.         }
  28.  
  29.         // append the total YES answers onto the message either way
  30.         $form['notification']['message'] .= "<br />Total <strong>YES</strong> answers: $yes</p>";
  31.  
  32.         // return modified form
  33.         return $form;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement