Advertisement
tylertervooren

GF Risk Test Full

Dec 10th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.75 KB | None | 0 0
  1. // CALCULATIONS TEST
  2. // http://www.gravityhelp.com/forums/topic/simple-calculations
  3. // change the # here to your form ID
  4. add_action('gform_pre_submission_filter_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.     // HERE we change the autoresponder
  74.     // Scoring logic for section scores to be individually placed in email.
  75.  
  76.     $score_overall = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  77.  
  78.         if(rgpost('input_122') > -30)
  79.             $score_overall = 'This is conditional answer #2.';
  80.         if(rgpost('input_122') > 0)
  81.             $score_overall = 'This is conditional answer #3.';
  82.         if(rgpost('input_122') > 30)
  83.             $score_overall = 'This is conditional answer #4.';
  84.  
  85.     $score_career = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  86.  
  87.         if(rgpost('input_112') > -3)
  88.             $score_career = 'This is conditional answer #2.';
  89.         if(rgpost('input_112') > 0)
  90.             $score_career = 'This is conditional answer #3.';
  91.         if(rgpost('input_112') > 3)
  92.             $score_career = 'This is conditional answer #4.';
  93.  
  94.     $score_work = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  95.  
  96.         if(rgpost('input_112') > -3)
  97.             $score_work = 'This is conditional answer #2.';
  98.         if(rgpost('input_112') > 0)
  99.             $score_work = 'This is conditional answer #3.';
  100.         if(rgpost('input_112') > 3)
  101.             $score_work = 'This is conditional answer #4.';
  102.  
  103.     $score_investment = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  104.  
  105.         if(rgpost('input_114') > -3)
  106.             $score_investment = 'This is conditional answer #2.';
  107.         if(rgpost('input_114') > 0)
  108.             $score_investment = 'This is conditional answer #3.';
  109.         if(rgpost('input_114') > 3)
  110.             $score_investment = 'This is conditional answer #4.';
  111.  
  112.     $score_money = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  113.  
  114.         if(rgpost('input_115') > -3)
  115.             $score_money = 'This is conditional answer #2.';
  116.         if(rgpost('input_115') > 0)
  117.             $score_money = 'This is conditional answer #3.';
  118.         if(rgpost('input_115') > 3)
  119.             $score_money = 'This is conditional answer #4.';
  120.  
  121.     $score_outgoingness = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  122.  
  123.         if(rgpost('input_116') > -3)
  124.             $score_outgoingness = 'This is conditional answer #2.';
  125.         if(rgpost('input_116') > 0)
  126.             $score_outgoingness = 'This is conditional answer #3.';
  127.         if(rgpost('input_116') > 3)
  128.             $score_outgoingness = 'This is conditional answer #4.';
  129.  
  130.     $score_conflict = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  131.  
  132.         if(rgpost('input_117') > -3)
  133.             $score_conflict = 'This is conditional answer #2.';
  134.         if(rgpost('input_117') > 0)
  135.             $score_conflict = 'This is conditional answer #3.';
  136.         if(rgpost('input_117') > 3)
  137.             $score_conflict = 'This is conditional answer #4.';
  138.  
  139.     $score_relationship_building = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  140.  
  141.         if(rgpost('input_118') > -3)
  142.             $score_relationship_building = 'This is conditional answer #2.';
  143.         if(rgpost('input_118') > 0)
  144.             $score_relationship_building = 'This is conditional answer #3.';
  145.         if(rgpost('input_118') > 3)
  146.             $score_relationship_building = 'This is conditional answer #4.';
  147.  
  148.     $score_risk_strategy = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  149.  
  150.         if(rgpost('input_119') > -3)
  151.             $score_risk_strategy = 'This is conditional answer #2.';
  152.         if(rgpost('input_119') > 0)
  153.             $score_risk_strategy = 'This is conditional answer #3.';
  154.         if(rgpost('input_119') > 3)
  155.             $score_risk_strategy = 'This is conditional answer #4.';
  156.  
  157.     $score_adventure = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
  158.  
  159.         if(rgpost('input_120') > -3)
  160.             $score_adventure = 'This is conditional answer #2.';
  161.         if(rgpost('input_120') > 0)
  162.             $score_adventure = 'This is conditional answer #3.';
  163.         if(rgpost('input_120') > 3)
  164.             $score_adventure = 'This is conditional answer #4.';
  165.  
  166.  
  167.         //This is where the message output will go. Does it replace the notification email set in GF or does it add to it?
  168.         $form['autoResponder']['message'] = $score_overall . "\n" . $score_career . "\n" . $score_work . "\n" . $score_investment . "\n" . $score_money . "\n" . $score_outgoingness . "\n" . $score_conflict . "\n" . $score_relationship_building . "\n" . $score_risk_strategy . "\n" . $score_adventure . "\nThank You!\n";
  169.         return $form;
  170. }
  171.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement