Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Chris Hajer 21 August 2012
- // reference http://www.gravityhelp.com/forums/topic/gravity-forms-quiz-help-needed#post-71088
- add_action('gform_pre_submission', 'social_media_quiz_score');
- function social_media_quiz_score ($form) {
- // change the number 2 here to your form ID
- // if this is not form 2, don't do any processing
- if($form['id'] != 2)
- return $form;
- // otherwise ...
- $score = 0;
- // my radio button inputs are numbered 1 to 20. Change the beginning
- // and ending number in this loop to match your actual input numbers
- for($i=1; $i<=20; $i++) {
- // add the value of the $_POST value for input 1 to input 20
- $input = 'input_' . $i;
- $score += rgpost($input);
- }
- // update the hidden 'Score' field with our calculated score
- $_POST['input_25'] = (int)($score * 5);
- switch($score) {
- // my "admin only" Rating field to hold the display message based on the score is input_24
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- $_POST['input_24'] = '5 or fewer correct answers: You really don\'t know much about social media.';
- break;
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- $_POST['input_24'] = '6 to 10 correct answers: I guess you know a little bit about social media.';
- break;
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- $_POST['input_24'] = '11 to 15 correct answers: You seem to know what you\'re talking about when it comes to social media.';
- break;
- default:
- $_POST['input_24'] = 'More than 15 correct answers: You might possibly know as much as I do about social media. Maybe I should hire you.';
- }
- // return the form object
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement