Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // http://www.gravityhelp.com/forums/topic/automatic-notification-if-multiple-radio-buttons-selected#post-93500
- // change the 228 here to your form ID
- add_filter('gform_pre_submission_filter_228', 'yes_or_no_notification');
- function yes_or_no_notification($form){
- // initialize value to prevent 'undefined' notice
- $yes = 0;
- // an array of all the radio button fields to be included in our yes/no check
- $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);
- // loop through all form fields looking for Yes answers
- foreach ($questions as $field) {
- if (rgpost("input_{$field}") == 'Yes'){
- // we're actually going to count the yes answers
- $yes++;
- }
- }
- // set the admin notification message based on the number of yes responses
- if($yes == 0) {
- $form['notification']['message'] = "<p>This is the admin notification if all questions were answered NO.";
- }
- else {
- $form['notification']['message'] = "<p>This is the admin notification if any question was answered YES.";
- }
- // append the total YES answers onto the message either way
- $form['notification']['message'] .= "<br />Total <strong>YES</strong> answers: $yes</p>";
- // return modified form
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement