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.

Random default value

  1. I want to set a default value of a field to a random number, lets say range 1 to 4.

    Does Gravity Forms allow PHP inside the default value field?

    For instance <?php echo rand(1, 4); ?>

    If not, is there a way to random display a set of fields?

    For instance, I have 40 questions, and I only want 10 of those questions to randomly show to the user.

    What is the best way to do this?

    Posted 12 years ago on Tuesday July 10, 2012 | Permalink
  2. David Peralty

    You can't put that as the default value of the field from within the editor, but you could easily use one of our hooks to be able to pre-populate that field. Make sure the field can be pre-populated, and then look at the code we have for gform_pre_render.

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

    As for the random questions and answers, you could then use the value in a hidden field set by your random call to determine which objects should be shown or hidden in Conditional Logic for your 40 questions. It wouldn't let you do things fully random, but it is a start.

    Posted 12 years ago on Tuesday July 10, 2012 | Permalink
  3. Hi Scotti,

    This might be helpful to you: http://gravitywiz.com/2012/07/20/random-fields-with-gravity-forms/

    Posted 12 years ago on Friday July 20, 2012 | Permalink