Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CALCULATIONS FOR RISK TAKING TEST
- // http://www.gravityhelp.com/forums/topic/simple-calculations
- // change the # here to your form ID
- add_action('gform_pre_submission_2', 'smart_risk_score');
- function smart_risk_score($form) {
- // set up one array for each step of the form
- // each array contains the input IDs of the fields we want to sum on each page
- // IDs do not need to be consecutive using this method
- $step_1_fields = array('input_5', 'input_6', 'input_8', 'input_7', 'input_9', 'input_10', 'input_11', 'input_12', 'input_14', 'input_15');
- $step_2_fields = array('input_16', 'input_18', 'input_19', 'input_20', 'input_21', 'input_22', 'input_23', 'input_24', 'input_26', 'input_27');
- $step_3_fields = array('input_28', 'input_29', 'input_30', 'input_31', 'input_32', 'input_33', 'input_34', 'input_35', 'input_36', 'input_37');
- $step_4_fields = array('input_38', 'input_40', 'input_41', 'input_42', 'input_43', 'input_44', 'input_45', 'input_46', 'input_47', 'input_48');
- $step_5_fields = array('input_49', 'input_50', 'input_51', 'input_52', 'input_53', 'input_54', 'input_55', 'input_56', 'input_57', 'input_58');
- $step_6_fields = array('input_59', 'input_61', 'input_62', 'input_63', 'input_64', 'input_65', 'input_66', 'input_67', 'input_68', 'input_69');
- $step_7_fields = array('input_70', 'input_72', 'input_73', 'input_74', 'input_75', 'input_76', 'input_77', 'input_78', 'input_79', 'input_80');
- $step_8_fields = array('input_81', 'input_83', 'input_84', 'input_85', 'input_86', 'input_87', 'input_88', 'input_89', 'input_90', 'input_91');
- $step_9_fields = array('input_92', 'input_93', 'input_94', 'input_95', 'input_96', 'input_97', 'input_98', 'input_99', 'input_100', 'input_121');
- // loop through inputs for each step individually
- $career = 0;
- foreach($step_1_fields as $value)
- // add each value to $step1_score
- $career += rgpost($value);
- $work = 0;
- foreach($step_2_fields as $value)
- $work += rgpost($value);
- $investment = 0;
- foreach($step_3_fields as $value)
- $investment += rgpost($value);
- $money = 0;
- foreach($step_4_fields as $value)
- $money += rgpost($value);
- $outgoingness = 0;
- foreach($step_5_fields as $value)
- $outgoingness += rgpost($value);
- $relationship_conflict = 0;
- foreach($step_6_fields as $value)
- $relationship_conflict += rgpost($value);
- $relationship_building = 0;
- foreach($step_7_fields as $value)
- $relationship_building += rgpost($value);
- $risk_strategy = 0;
- foreach($step_8_fields as $value)
- $risk_strategy += rgpost($value);
- $adventure = 0;
- foreach($step_9_fields as $value)
- $adventure += rgpost($value);
- // total of the subtotals for each step
- $overall = $career + $work + $investment + $money + $outgoingness + $relationship_conflict + $relationship_building + $risk_strategy + $adventure;
- // submit these calculated values to the form so they are stored with the entry and can be used in the confirmation
- $_POST['input_112'] = $career;
- $_POST['input_113'] = $work;
- $_POST['input_114'] = $investment;
- $_POST['input_115'] = $money;
- $_POST['input_116'] = $outgoingness;
- $_POST['input_117'] = $relationship_conflict;
- $_POST['input_118'] = $relationship_building;
- $_POST['input_119'] = $risk_strategy;
- $_POST['input_120'] = $adventure;
- $_POST['input_122'] = $overall;
- // be sure to return the form when we're done
- return $form;
- }
- //EMAIL NOTIFICATION FUNCTION
- add_filter('gform_pre_submission_2', 'conditional_message');
- function conditional_message($form) {
- //Scoring logic for section scores to be individually placed in email.
- $score_overall = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
- if(rgpost('input_122') > -30)
- $score_overall = 'This is conditional answer #2.';
- if(rgpost('input_122') > 0)
- $score_overall = 'This is conditional answer #3.';
- if(rgpost('input_122') > 30)
- $score_overall = 'This is conditional answer #4.';
- $score_career = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
- if(rgpost('input_112') > -3)
- $score_career = 'This is conditional answer #2.';
- if(rgpost('input_112') > 0)
- $score_career = 'This is conditional answer #3.';
- if(rgpost('input_112') > 3)
- $score_career = 'This is conditional answer #4.';
- $score_work = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
- if(rgpost('input_112') > -3)
- $score_work = 'This is conditional answer #2.';
- if(rgpost('input_112') > 0)
- $score_work = 'This is conditional answer #3.';
- if(rgpost('input_112') > 3)
- $score_work = 'This is conditional answer #4.';
- $score_investment = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
- if(rgpost('input_114') > -3)
- $score_investment = 'This is conditional answer #2.';
- if(rgpost('input_114') > 0)
- $score_investment = 'This is conditional answer #3.';
- if(rgpost('input_114') > 3)
- $score_investment = 'This is conditional answer #4.';
- $score_money = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
- if(rgpost('input_115') > -3)
- $score_money = 'This is conditional answer #2.';
- if(rgpost('input_115') > 0)
- $score_money = 'This is conditional answer #3.';
- if(rgpost('input_115') > 3)
- $score_money = 'This is conditional answer #4.';
- $score_outgoingness = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
- if(rgpost('input_116') > -3)
- $score_outgoingness = 'This is conditional answer #2.';
- if(rgpost('input_116') > 0)
- $score_outgoingness = 'This is conditional answer #3.';
- if(rgpost('input_116') > 3)
- $score_outgoingness = 'This is conditional answer #4.';
- $score_conflict = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
- if(rgpost('input_117') > -3)
- $score_conflict = 'This is conditional answer #2.';
- if(rgpost('input_117') > 0)
- $score_conflict = 'This is conditional answer #3.';
- if(rgpost('input_117') > 3)
- $score_conflict = 'This is conditional answer #4.';
- $score_relationship_building = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
- if(rgpost('input_118') > -3)
- $score_relationship_building = 'This is conditional answer #2.';
- if(rgpost('input_118') > 0)
- $score_relationship_building = 'This is conditional answer #3.';
- if(rgpost('input_118') > 3)
- $score_relationship_building = 'This is conditional answer #4.';
- $score_risk_strategy = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
- if(rgpost('input_119') > -3)
- $score_risk_strategy = 'This is conditional answer #2.';
- if(rgpost('input_119') > 0)
- $score_risk_strategy = 'This is conditional answer #3.';
- if(rgpost('input_119') > 3)
- $score_risk_strategy = 'This is conditional answer #4.';
- $score_adventure = 'Your answers made absolutely no sense at all. I award you no points and may God have mercy on your soul.';
- if(rgpost('input_120') > -3)
- $score_adventure = 'This is conditional answer #2.';
- if(rgpost('input_120') > 0)
- $score_adventure = 'This is conditional answer #3.';
- if(rgpost('input_120') > 3)
- $score_adventure = 'This is conditional answer #4.';
- //This is where the message output will go. Does it replace the notification email set in GF or does it add to it?
- $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';
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement