Hello, I have created a quiz with scores calculation and several confirmation messages using the instruction from http://www.gravityhelp.com/forums/topic/mathematics-to-gravity-forms.
My first quiz question is a Yes or No (with values 1 and 0). I have six total confirmation messages to include, 3 for scores IF the first question is YES and 3 IF the first question is NO. My code is shown below, which currently includes the 3 confirmations for YES, I would like to add a condition here, and then use the same condition for NO and add the 3 confirmations for NO.
Any help would be greatly appreciated.
add_action('gform_pre_submission', 'ch_total_quiz_values');
function ch_total_quiz_values ($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<=14; $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'] = $score;
switch($score) {
// my "admin only" Rating field to hold the display message based on the score in input_24
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
$_POST['input_24'] = 'Response Here';
break;
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
$_POST['input_24'] = 'Response Here.';
break;
case 30:
case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
case 41:
case 42:
$_POST['input_24'] = 'Response Here';
break;
}
return $form;
}