Created
June 24, 2012 04:04
-
-
Save rossteasley/2981540 to your computer and use it in GitHub Desktop.
Gravity Forms Quiz code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.gravityhelp.com/forums/topic/mathematics-to-gravity-forms | |
add_action('gform_pre_submission', 'ch_total_quiz_values'); | |
function ch_total_quiz_values ($form) { | |
// change the number 20 here to your form ID | |
// if this is not form 20, don't do any processing | |
if($form['id'] != 3) | |
return $form; | |
// otherwise ... | |
$score = 0; | |
// my inputs are numbered 1 to 18. Change the beginning | |
// and ending number in this loop to match your actual input numbers | |
for($i=1; $i<=18; $i++) { | |
// add the value of the $_POST value for input 1 to input 18 | |
$input = 'input_' . $i; | |
$score += rgpost($input); | |
} | |
// update the hidden 'Score' field with our calculated score | |
$_POST['input_19'] = $score; | |
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: | |
case 6: | |
case 7: | |
case 8: | |
$_POST['input_20'] = '1-8: Tourist'; | |
break; | |
case 9: | |
case 10: | |
case 11: | |
case 12: | |
case 13: | |
case 14: | |
$_POST['input_20'] = '9-14: Poser'; | |
break; | |
case 15: | |
case 16: | |
case 17: | |
case 18: | |
case 19: | |
case 20: | |
case 21: | |
case 22: | |
case 23: | |
case 24: | |
case 25: | |
$_POST['input_20'] = '15-25: Transplant'; | |
break; | |
case 26: | |
case 27: | |
case 28: | |
case 29: | |
case 30: | |
case 31: | |
$_POST['input_20'] = '26-31: Local'; | |
break; | |
default: | |
$_POST['input_20'] = '32-33: Native'; | |
} | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment