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.

Making a result page based on conditional logic

  1. I hope that you can help me, I would like to use Gravity forms to make a test/quiz, and the test results should be based on the information entered into form during testing.

    I want to build the result page like this:
    Q1 You can chose answer A, B or C, depending on the users choice, the result page will add Result 1, 2 or 3, the same for Q2 and so on.
    For one or two of the results, they will depend on the specific combination of two answers.

    Looking in the forums, I have found some topics that cover some of this, but I am not sure where to start.

    Getting this to work is my first challenge, any help is appreciated, as I am not that robust in programming.

    I just want to mention this, because it might affect how I should reach the above goal:
    When the user sees the test results, I would like to give them the opportunity to e-mail the results to them selves, and chose to be contacted by me or my partner to discuss the results, and see if they want to buy some time from our consulting service.
    I would like to do this as a form with those few options.

    I really hope that you can help point me in the right direction. Thanks

    Posted 13 years ago on Friday August 26, 2011 | Permalink
  2. Hi Miranova,

    Did you want to direct them to a custom page based on their submitted values? or customize the confirmation message based on the submitted values?

    With either option, take a look at the gform_confirmation filter which will let you modify the confirmation message (supports full HTML) or the redirect page.

    Posted 13 years ago on Friday August 26, 2011 | Permalink
  3. Hi David

    Thank you for your quick reply! :-)

    What I want to do really depends on what is possible, and then what is the smartest way to do it.

    I think that I want to customize the confirmation message based on the submitted values.

    The confirmation message should be build up with a different text based on the submitted values. First I want to look at the answer for question one, depending on the answer to question one (the submitted value), a corresponding text to that answer should be written on the confirmation message. Then I move on to question two look at the submitted value, and add a text based on that, so that both the text based on the submitted value to question one and the text based on the submitted value to question two is in the confirmation message. I want to keep on looking at submitted values to the different questions, and add text to the confirmation message, until I have been through all the questions. I want to end up with a small report for the user.

    I have already designed this test on paper, and I have 90 different combinations of the confirmation message.

    I have been looking at one of your answers to an earlier question, and I am thinking that might be the way to go, but unfortunately the link to the test form is not working any more.
    http://www.gravityhelp.com/forums/topic/conditional-notification-mesasage?message=closed#post-7967

    Is there a better way than what you suggested in the above link?

    Posted 13 years ago on Friday August 26, 2011 | Permalink
  4. If you want to change the displayed confirmation message, based on the values entered, I think you can do that. As always, there are multiple ways this can be accomplished. If you want to store this information in the entry at all (as a record of what you said to this particular visitor, for example) you would want to use the gform_pre_submission_filter.

    If you just want to change what the confirmation text is before it's displayed, you can use the gform_confirmation http://www.gravityhelp.com/documentation/page/Gform_confirmation hook.

    You mentioned changing the confirmation message. This example will change the confirmation message based on their form entries. You will have to expand on it to make it work in your situation, but the process is here.

    Example form:
    http://guitar.chrishajer.com/test-of-conditional-confirmation-text/

    Code to add to functions.php:
    http://pastebin.com/EJEFYPW1

    If you submit the form, you will see the messages change based on your selections. Use the browser back button and make a change, then submit again to see the confirmation message change. You won't get any email from the form.

    Posted 13 years ago on Sunday August 28, 2011 | Permalink
  5. Hi Chris

    Thank you for you suggestions and example! :-)

    I have a small problem getting it to work, but after implementing the exact same form as you have made, and pasting you example code into my functions.php and doing some testing, I think I know what my problem is.
    In my own form, I have moved some of the fields around after inserting them, and my problem is that I do not know what number to put into $lead[*] (They are no longer in the order that I created them in, so I can't just count them) Can you help me to locate the different fields id's so that I can use your code with my own form, without having to make a new form? (where I will know the id of the different fields)

    Thanks
    Carsten

    Posted 13 years ago on Tuesday August 30, 2011 | Permalink
  6. View the source for the page and look for the name='input_ attributes in the form. The number after the input_ is the number you need for the lead.

    Screenshot: http://minus.com/mIfJfH9qY

    Posted 13 years ago on Tuesday August 30, 2011 | Permalink
  7. Also, Carsten, finding the field ID and field type is much easier in 1.6. It's right there when you hover over the field in the form builder. For now, we have to "view source" in the browser.

    Posted 13 years ago on Tuesday August 30, 2011 | Permalink
  8. Hi Chris

    Thank you for the explanation and screenshot, I have gotten this to work with my own form, and I am very happy about that Thanks! :-)

    But now I want to do more. :-)

    1. I would like to use some of the submitted values in the notification text. One example is the name that the users enter in my form, I would like to address them in the notification "Hi (first name) thank you for taking our test, here are the results:" - Can I do that? If I can, how do I accomplish that?

    2. Maybe the same as above. I would like to use some of the values that the users enter in my form, in my response, right in the middle of some of the text that I write to them, adding the values, that they enter them selves, will help to make the result more valuable for the user.

    3. This is a bit more tricky I think - I would like to use the numbers that I collect in the form, to make some calculations, and return the results to the users in the notification, right in the middle of the text in the notification. Is that possible, if yes can you point me in the right direction?
    (One example would be to calculate the BMI, using the numbers for weight and hight that the user enters into the form) - This is not what I do, just the best example that I could think of.

    I just want to let you know that you have already helped a lot, thanks! :-)
    Carsten

    Posted 13 years ago on Wednesday August 31, 2011 | Permalink
  9. 1) Yes. Use the "Insert form field" drop down when creating your notification message. It inserts merge tags which are replaced with the actual field value when the notification is sent.

    2) Same thing. The form confirmation has an "Insert form field" drop down that lets you insert field merge tags into your thank you message.

    3) Gravity Forms doesn't currently perform calculations. You'd have to do this as a customization. It isn't a built in feature.

    Posted 13 years ago on Wednesday August 31, 2011 | Permalink
  10. Hi Carl

    Thank you for your reply, I'm already creating a "special" confirmation message based on the example code that Chris provided, so I can not use the "Insert form field" because my confirmation message is being build using the "conditional logic" (example code from Chris) that I have inserted into my functions.php.
    So I need to know if I can do these things using the example code that you can see here: http://pastebin.com/EJEFYPW1 (does that make sense?)

    Thanks
    Carsten

    Posted 13 years ago on Wednesday August 31, 2011 | Permalink
  11. If you are redirecting to a page and need to show form field values on that page you would have to pass the form field values to that page and then read the values from the query string and display them.

    Posted 13 years ago on Wednesday August 31, 2011 | Permalink
  12. Carsten, all these things are possible and I have examples around here somewhere. I will find them for you and post them tomorrow. Items 1 and 2 are the same, and I have an example with some math as well. I'll check in tomorrow with the examples.

    Posted 13 years ago on Wednesday August 31, 2011 | Permalink
  13. Hi Chris

    That sounds great, I am looking forward to this, I have tried searching, but I'am not sure I know what to search for. So thanks!

    Carsten

    Posted 13 years ago on Thursday September 1, 2011 | Permalink
  14. Here is an explanation of how to total up the values yes/no and using that in the confirmation message. You can adapt this to insert the math results into the notification message rather than the confirmation screen.

    http://www.gravityhelp.com/forums/topic/mathematics-to-gravity-forms#post-32566

    You can replace the sum with whatever math you want.

    Here's an explanation of how to change the confirmation email.
    http://www.gravityhelp.com/forums/topic/conditional-logic-for-user-notifications#post-32358

    You have a bunch of little pieces to glue together. I think all the information you need is here. If not, please let me know.

    Posted 13 years ago on Thursday September 1, 2011 | Permalink
  15. Hi Chris

    I have looked through the information that you have linked to, and I must admit that I can not get it to work, together with the example code that you provided me earlier in this post.

    I will try to explain what it is that I want to do:
    input_7 holds some information that I would like to post in the custom notification message, that I have made using your example code. What I need now is a clue on how to post the information that is in input_7, I can not figure that out looking at the posts you have provided links to.

    I am guessing that the {My Field:7:value} is used when creating a confirmation message in Gravity Forms admin in Wordpress, but I am creating the message in functions.php

    I was thinking something like this: $confirmation .= "Hi " $lead[7] "you're a Photoshop person, comfortable in the digital world of RGB.</p>";
    Where the value in input_7 would be the name.

    Can you help me to do something like that?

    The next would be to add up input_9 and input_10 and display that in a similar way ` $score = $lead[9]+$lead[10];
    $confirmation .= "We have calculated that " $score "is the sum of your values added together .</p>"; `

    Can you help me to do something like that?

    Thanks
    Carsten

    Posted 13 years ago on Thursday September 1, 2011 | Permalink
  16. Hi

    I am very happy with the level of support I have received this far! If my questions are to specific, or in some way outside of the scope of support questions, please let me know,

    Would it change anything if I upgraded my license to a developer license, so I will be able to receive priority support?

    I am very happy with your support, I think that you have already gone very far in supporting me, and I can perfectly understand if I should pay extra for more support on this topic, just let me know. :-)

    If my programing skills were a little better, I probably would not need this much help.

    Thanks
    Carsten

    Posted 13 years ago on Thursday September 1, 2011 | Permalink
  17. Hi Carsten. We would love if you upgraded to a Developer License! But it's not required to receive support here. Support requests are prioritized with problems and simple customizations coming first, with more complex customizations (such as yours) coming after. I will take a look at this again on Friday and see if I can provide a more useful example to you. The pieces I linked you too were all sort of just a nudge in the right direction, but I can work up more thorough examples for you.

    Do you want to focus on the notification email or the confirmation message shown to the visitor after form submission?

    The explanation of what you want to accomplish is pretty clear. If the form is live, please post a link to it. If you have some portion of it built, please export it as XML and send it to me at chris@rocketgenius.com, or post it in a publicly accessible location where I can download it and install it so I have something relevant to start with. Thanks.

    Posted 13 years ago on Friday September 2, 2011 | Permalink
  18. Hi Chris

    Thank for your offer of writing you an e-mail, I have taken you up on that, and just send you an e-mail with my remaining questions, and the export of the form, and the code that I have in my functions.php

    Looking forward to hearing from you :-)

    I completely understand that you need to prioritize, I just did not know that. :-)

    Thanks
    Carsten

    Posted 13 years ago on Friday September 2, 2011 | Permalink
  19. Carsten, I just sent you an email.

    Posted 13 years ago on Saturday September 3, 2011 | Permalink
  20. Hi Chris

    Thank you for your mail.

    As Chris pointed out to me, in his e-mail, my problem is solved, and my new questions belong in a new post. :-) (I had some new questions in the mail)

    I just want to share what I did to solve my latest questions, I have used Chris's example code, and build on that, these examples uses that code:
    To insert text I used this method:

    $confirmation .= "This is the line you write to the screen," . $lead[1] . " Writes the content of $lead[1] in the message.</p>"

    Depending on the use of " or ' You should use:

    " . $lead[1] . " or ' . $lead[1] . '

    And math:

    $Score = $lead[1] + $lead[2] + $lead[3];

    Print score:

    " . $Score . "

    Thank you Chris and the rest of the support team for all your help!

    P.s.
    I have tried to format the inserted code in my messages, but I can not get that to work, sorry

    Posted 13 years ago on Monday September 5, 2011 | Permalink
  21. Carsten, to paste code, if it's short, use the backtick, which is to the left of the number keys, above the tab, below the ESC, on US keyboards.

    http://superuser.com/questions/203138/backtick-on-an-italian-macbook-pros-keyboard/203140#203140 (includes photo)

    Thanks for the update and I look forward to reading your other topics.

    Posted 13 years ago on Monday September 5, 2011 | Permalink

This topic has been resolved and has been closed to new replies.