SHARE
TWEET

GF Risk Test Full (Broken)

tylertervooren Dec 1st, 2011 17 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // CALCULATIONS FOR RISK TAKING TEST
  2. // http://www.gravityhelp.com/forums/topic/simple-calculations
  3. // change the # here to your form ID
  4. add_action('gform_pre_submission_2', 'smart_risk_score');
  5. function smart_risk_score($form) {
  6.  
  7.         // set up one array for each step of the form
  8.         // each array contains the input IDs of the fields we want to sum on each page
  9.         // IDs do not need to be consecutive using this method
  10.         $step_1_fields = array('input_5',  'input_6',  'input_8',  'input_7',  'input_9',  'input_10',  'input_11',  'input_12',  'input_14', 'input_15');
  11.         $step_2_fields = array('input_16', 'input_18', 'input_19', 'input_20', 'input_21', 'input_22', 'input_23', 'input_24', 'input_26', 'input_27');
  12.         $step_3_fields = array('input_28', 'input_29', 'input_30', 'input_31', 'input_32', 'input_33', 'input_34', 'input_35', 'input_36', 'input_37');
  13.         $step_4_fields = array('input_38', 'input_40', 'input_41', 'input_42', 'input_43', 'input_44', 'input_45', 'input_46', 'input_47', 'input_48');
  14.         $step_5_fields = array('input_49', 'input_50', 'input_51', 'input_52', 'input_53', 'input_54', 'input_55', 'input_56', 'input_57', 'input_58');
  15.         $step_6_fields = array('input_59', 'input_61', 'input_62', 'input_63', 'input_64', 'input_65', 'input_66', 'input_67', 'input_68', 'input_69');
  16.         $step_7_fields = array('input_70', 'input_72', 'input_73', 'input_74', 'input_75', 'input_76', 'input_77', 'input_78', 'input_79', 'input_80');
  17.         $step_8_fields = array('input_81', 'input_83', 'input_84', 'input_85', 'input_86', 'input_87', 'input_88', 'input_89', 'input_90', 'input_91');
  18.         $step_9_fields = array('input_92', 'input_93', 'input_94', 'input_95', 'input_96', 'input_97', 'input_98', 'input_99', 'input_100', 'input_121');
  19.  
  20.         // loop through inputs for each step individually
  21.         $career = 0;
  22.         foreach($step_1_fields as $value)
  23.                 // add each value to $step1_score
  24.                 $career += rgpost($value);
  25.  
  26.         $work = 0;
  27.         foreach($step_2_fields as $value)
  28.                 $work += rgpost($value);
  29.  
  30.         $investment = 0;
  31.         foreach($step_3_fields as $value)
  32.                 $investment += rgpost($value);
  33.  
  34.         $money = 0;
  35.         foreach($step_4_fields as $value)
  36.                 $money += rgpost($value);
  37.  
  38.         $outgoingness = 0;
  39.         foreach($step_5_fields as $value)
  40.                 $outgoingness += rgpost($value);
  41.  
  42.         $relationship_conflict = 0;
  43.         foreach($step_6_fields as $value)
  44.                 $relationship_conflict += rgpost($value);
  45.  
  46.         $relationship_building = 0;
  47.         foreach($step_7_fields as $value)
  48.                 $relationship_building += rgpost($value);
  49.  
  50.         $risk_strategy = 0;
  51.         foreach($step_8_fields as $value)
  52.                 $risk_strategy += rgpost($value);
  53.  
  54.         $adventure = 0;
  55.         foreach($step_9_fields as $value)
  56.                 $adventure += rgpost($value);
  57.  
  58.         // total of the subtotals for each step
  59.         $overall = $career + $work + $investment + $money + $outgoingness + $relationship_conflict + $relationship_building + $risk_strategy + $adventure;
  60.  
  61.         // submit these calculated values to the form so they are stored with the entry and can be used in the confirmation
  62.         $_POST['input_112'] = $career;
  63.         $_POST['input_113'] = $work;
  64.         $_POST['input_114'] = $investment;
  65.         $_POST['input_115'] = $money;  
  66.         $_POST['input_116'] = $outgoingness;   
  67.         $_POST['input_117'] = $relationship_conflict;  
  68.         $_POST['input_118'] = $relationship_building;  
  69.         $_POST['input_119'] = $risk_strategy;  
  70.         $_POST['input_120'] = $adventure;      
  71.         $_POST['input_122'] = $overall;
  72.  
  73.         // be sure to return the form when we're done
  74.         return $form;
  75. }
  76.  
  77. //EMAIL NOTIFICATION FUNCTION
  78. add_filter('gform_pre_submission_2', 'conditional_message');
  79. function conditional_message($form) {
  80.  
  81.  
  82. //Scoring logic for section scores to be individually placed in email.
  83.  
  84. $score_overall = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  85.  
  86.         if(rgpost('input_122') > -30)
  87.                 $score_overall = 'This is conditional answer #2.';
  88.         if(rgpost('input_122') > 0)
  89.                 $score_overall = 'This is conditional answer #3.';
  90.         if(rgpost('input_122') > 30)
  91.                 $score_overall = 'This is conditional answer #4.';
  92.  
  93. $score_career = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  94.  
  95.         if(rgpost('input_112') > -3)
  96.                 $score_career = 'This is conditional answer #2.';
  97.         if(rgpost('input_112') > 0)
  98.                 $score_career = 'This is conditional answer #3.';
  99.         if(rgpost('input_112') > 3)
  100.                 $score_career = 'This is conditional answer #4.';
  101.  
  102. $score_work = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  103.  
  104.         if(rgpost('input_112') > -3)
  105.                 $score_work = 'This is conditional answer #2.';
  106.         if(rgpost('input_112') > 0)
  107.                 $score_work = 'This is conditional answer #3.';
  108.         if(rgpost('input_112') > 3)
  109.                 $score_work = 'This is conditional answer #4.';
  110.  
  111. $score_investment = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  112.  
  113.         if(rgpost('input_114') > -3)
  114.                 $score_investment = 'This is conditional answer #2.';
  115.         if(rgpost('input_114') > 0)
  116.                 $score_investment = 'This is conditional answer #3.';
  117.         if(rgpost('input_114') > 3)
  118.                 $score_investment = 'This is conditional answer #4.';
  119.  
  120. $score_money = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  121.  
  122.         if(rgpost('input_115') > -3)
  123.                 $score_money = 'This is conditional answer #2.';
  124.         if(rgpost('input_115') > 0)
  125.                 $score_money = 'This is conditional answer #3.';
  126.         if(rgpost('input_115') > 3)
  127.                 $score_money = 'This is conditional answer #4.';
  128.  
  129. $score_outgoingness = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  130.  
  131.         if(rgpost('input_116') > -3)
  132.                 $score_outgoingness = 'This is conditional answer #2.';
  133.         if(rgpost('input_116') > 0)
  134.                 $score_outgoingness = 'This is conditional answer #3.';
  135.         if(rgpost('input_116') > 3)
  136.                 $score_outgoingness = 'This is conditional answer #4.';
  137.  
  138. $score_conflict = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  139.  
  140.         if(rgpost('input_117') > -3)
  141.                 $score_conflict = 'This is conditional answer #2.';
  142.         if(rgpost('input_117') > 0)
  143.                 $score_conflict = 'This is conditional answer #3.';
  144.         if(rgpost('input_117') > 3)
  145.                 $score_conflict = 'This is conditional answer #4.';
  146.  
  147. $score_relationship_building = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  148.  
  149.         if(rgpost('input_118') > -3)
  150.                 $score_relationship_building = 'This is conditional answer #2.';
  151.         if(rgpost('input_118') > 0)
  152.                 $score_relationship_building = 'This is conditional answer #3.';
  153.         if(rgpost('input_118') > 3)
  154.                 $score_relationship_building = 'This is conditional answer #4.';
  155.  
  156. $score_risk_strategy = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  157.  
  158.         if(rgpost('input_119') > -3)
  159.                 $score_risk_strategy = 'This is conditional answer #2.';
  160.         if(rgpost('input_119') > 0)
  161.                 $score_risk_strategy = 'This is conditional answer #3.';
  162.         if(rgpost('input_119') > 3)
  163.                 $score_risk_strategy = 'This is conditional answer #4.';
  164.  
  165. $score_adventure = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  166.  
  167.         if(rgpost('input_120') > -3)
  168.                 $score_adventure = 'This is conditional answer #2.';
  169.         if(rgpost('input_120') > 0)
  170.                 $score_adventure = 'This is conditional answer #3.';
  171.         if(rgpost('input_120') > 3)
  172.                 $score_adventure = 'This is conditional answer #4.';
  173.  
  174.  
  175.         //This is where the message output will go. Does it replace the notification email set in GF or does it add to it?
  176.  
  177.         $form['autoResponder']['message'] .= '$score_overall . " " . $score_career . " " . $score_work . " " . $score_investment . " " . $score_money . " " . $score_outgoingness . " " $score_conflict . " " . $score_relationship_building . " " . $score_risk_strategy . " " . $score_adventure';
  178.  
  179.         return $form;
  180. }
  181.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top