PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Conditional Confirmation

  1. stature
    Member

    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;
    }
    Posted 11 years ago on Thursday April 25, 2013 | Permalink
  2. stature
    Member

    Basically what I want to do is this:

    IF question#1 is NO (value = 0), AND score totals 6 to 18 THEN show Confirmation#1
    IF question#1 is YES (value = 1), AND score totals 7 to 18 THEN show Confirmation #2
    IF question#1 is NO (value = 0), AND score totals 19 to 29 THEN show Confirmation#3
    IF question#1 is YES (value = 1), AND score totals 19 to 29 THEN show Confirmation #4
    IF question#1 is NO (value = 0), AND score totals 30 to 41 THEN show Confirmation#5
    IF question#1 is YES (value = 1), AND score totals 30 to 42 THEN show Confirmation #6

    I believe it should be a simple solution to include in my code example about the first case of each.
    If someone could help with a general example for one instance I can apply to the rest of them.

    Thanks again for any assistance!

    Posted 11 years ago on Thursday April 25, 2013 | Permalink
  3. stature
    Member

    Bump to the top - any help?

    Posted 11 years ago on Wednesday May 1, 2013 | Permalink
  4. stature
    Member

    It's been a week without a response - should I restructure my question? Hoping to get any help before the weekend!! Thanks to anyone who replies :-)

    Posted 11 years ago on Friday May 3, 2013 | Permalink
  5. stature
    Member

    I'm trying to call the field ID and associated value with a IF statement, and not quite getting it.

    How can I call a specific field ID and Value?
    Replacing the ID and VALUE is not working for me: $field['ID']='VALUE'

    Where would I place the corrected code in the example below to have two separate confirmation messages? One if value = 1 and another if value = 2.

    $_POST['input_25'] = $score;
            switch($score) {
                    // my "admin only" Rating field to hold the display message based on the score in input_24
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                            $_POST['input_24'] = '5 or fewer correct answers: You\'re a complacent leader who ignores changes in the environment.';
    Posted 11 years ago on Wednesday May 8, 2013 | Permalink
  6. stature
    Member

    Any help available? Please and thanks :-)

    Posted 11 years ago on Thursday May 9, 2013 | Permalink
  7. David Peralty

    Have you tried our Quiz Add-on? It might be a shortcut to what you want to do...

    Posted 11 years ago on Saturday May 11, 2013 | Permalink