Guest User

smgrader-quiz-scoring

a guest
Aug 14th, 2012
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // http://www.gravityhelp.com/forums/topic/mathematics-to-gravity-forms
  2. add_action('gform_pre_submission', 'ch_total_quiz_values');
  3. function ch_total_quiz_values ($form) {
  4. // change the number 20 here to your form ID
  5. // if this is not form 20, don't do any processing
  6. if($form['id'] != 20)
  7. return $form;
  8.  
  9. // otherwise ...
  10. $score = 0;
  11. // my radio button inputs are numbered 1 to 20. Change the beginning
  12. // and ending number in this loop to match your actual input numbers
  13. for($i=1; $i<=20; $i++) {
  14. // add the value of the $_POST value for input 1 to input 20
  15. $input = 'input_' . $i;
  16. $score += rgpost($input);
  17. }
  18. // update the hidden 'Score' field with our calculated score
  19. $_POST['input_25'] = $score;
  20. switch($score) {
  21. // my "admin only" Rating field to hold the display message based on the score is input_24
  22. case 0:
  23. case 1:
  24. case 2:
  25. case 3:
  26. case 4:
  27. case 5:
  28. $_POST['input_24'] = '5 or fewer correct answers: You\'re a Social Media beginner.';
  29. break;
  30. case 6:
  31. case 7:
  32. case 8:
  33. case 9:
  34. case 10:
  35. $_POST['input_24'] = '6 to 10 correct answers: You\'re a Social Media intermediate.';
  36. break;
  37. case 11:
  38. case 12:
  39. case 13:
  40. case 14:
  41. case 15:
  42. $_POST['input_24'] = '11 to 15 correct answers: You\'re a Social Media pro.';
  43. break;
  44. default:
  45. $_POST['input_24'] = 'More than 15 correct answers: You\'re a Social Media Expert';
  46. }
  47. return $form;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment