How to add Gravity Forms fields in gform_pre_render()

I have a multi page Gravity Form that presents a series of questions by way of a radio button.

Which of the following would you choose?

    o  Choice #1
    o  Choice #2

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

Each question and choice set is configured using custom fields (Advanced Custom Fields). I'm able to iterate through all of these questions and choices just fine from within the gform_pre_render filter and now I want to create the needed Gravity Form fields on the fly.

Specifically, there will be a page field and radio button field for every question.

I really have tried just about every search criteria I can think of on Google and scoured through documentation on Gravity Help, but I just don't see an example of adding fields dynamically.

Can someone shine a light for me? :P


ANSWERS:


You can create a field with GFFields::create(). Here's a rough example (assumes you are within the gform_pre_render filter.

$props = array( 
    'id' => 123,
    'label' => 'My Field Label',
    'type' => 'text'
);
$field = GF_Fields::create( $props );
array_push( $form['fields'], $field );

There are probably more properties you will need to specify to get the field working. I would recommend using print_r() on an existing field to get an idea of all the properties available. You will also want to make sure your field IDs are unique.

Lastly, in order for data to be captured from these existing fields, you will probably want to also add your dynamic fields via the gform_pre_validation filter as well.



 MORE:


 ? update_user_meta/add_user_meta for all user accounts with loop
 ? update_user_meta/add_user_meta for all user accounts with loop
 ? update_user_meta/add_user_meta for all user accounts with loop
 ? How to update user meta for multiple meta_key in wordpress
 ? Using an array of users with update_user_meta
 ? Updating user metadata with custom profile infrmation
 ? Foreach Loop Not Display All Entries
 ? Get current month posts in Wordpress loop
 ? How can I remove the password confirmation field in Gravity Forms User Registration in Wordpress?
 ? PHP - How do I Add Exceptions or Exclude Pages, Sub Pages, or Objects from a "For Each" Loop?