0
votes

I see a lot of discussion about dynamically populating fields, but not much of any about dynamically creating fields. I have what appears to be a simple form. It consists of an arbitrary number of questions with a set of possible choices. For example:

Which of the following would you choose?

    o  Choice #1
    o  Choice #2

    +----------+   +----------+  
    |   BACK   |   |   NEXT   |  
    +----------+   +----------+  

The form would require a radio button to be selected, the NEXT button becomes active and the user proceeds to the next question.

There are dozens of questions with each question on its own page of a multi page form. It's a lot of configuration within Gravity Forms. Since each page will be identical in layout and functionality I am wondering if there is a suggested way of outputting this form dynamically.

Is there a way of creating form fields dynamically from within a hook/action in functions.php?

The reason I am asking is to explore the possibility of wrapping a Gravity Forms shortcode with one that allows configuration of the questions and answers.

1
Hi @rwkiii could you share your experience using the answer below? Specifically, were you ask to export your dynamic fields? - Daniel

1 Answers

2
votes

The gform_pre_render filter is called on every form page load. You can manipulate the $form['fields'] to add/remove/modify the form's fields. This includes adding pages and fields on the fly (pages are just a field with the type "page").