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.

use radio buttons to pre-populate a hidden field

  1. dear sir/madam,
    my compliments for the best wordpress plugin ever!

    I want to dynamically populate a hidden field, or admin only field called "output".
    To do this I want to use 2 questions using radio buttons.
    Question 1 has 2 answers: "yes" (I gave it a value "4"), and "no" (value 2).
    Question 2 has 3 answers: "yes" (value 4), "sometimes" (value 3) and "no" (value 2).

    I want to use the sum of the values of question 1 and 2 and populate the dynamic field "output" like this:
    if question 1 + question 2 = 8 => "everything"
    if question 1 + question 2 = 7 => "almost everything"
    if question 1 + question 2 = 6 => "sometimes"
    if question 1 + question 2 = 5 => "sure thing"
    if question 1 + question 2 = 4 => "no"

    I tried to do this using a hook, but I can't figure it out.

    Can someone help me with this?

    Posted 12 years ago on Thursday February 9, 2012 | Permalink
  2. You would need to do this using the gform_pre_submission hook so that it happens after the form is submitted but before the entry is created and notifications are sent.

    You would use the gform_pre_submission hook and write custom code to 1) read the values of your radio buttons 2) perform whatever calculation you want to perform and 3) populate the hidden field on your form with whatever you want the value to be based on 1 & 2.

    The gform_pre_submission hook is documented here:

    http://www.gravityhelp.com/documentation/page/Gform_pre_submission

    It has access to the form object which contains all of the submitted form data.

    The documentation has an example that shows how to populate the value of a field using the gform_pre_submission hook, although your use case is a little more complex (although still nothing big) as you want to first perform a calculation, etc. You would use standard PHP to do this.

    Posted 12 years ago on Thursday February 9, 2012 | Permalink

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