Of course.
Here is the code:
// Adjust your form ID
add_filter( 'gform_form_post_get_meta_2', 'add_my_field' );
function add_my_field( $form )
{
// Create a Section header for Family Household Member
$FamilyMember = GF_Fields::create( array(
'type' => 'section',
'id' => 1001, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => 'Household Member',
'pageNumber' => 2, // Ensure this is correct
) );
// Create a Single Line text field for the family member's first name
$FamilyFirstName = GF_Fields::create( array(
'type' => 'text',
'id' => 1002, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => 'First Name',
'pageNumber' => 2, // Ensure this is correct
) );
// Create a Single Line text field for the family member's middle name
$FamiliyMiddleName = GF_Fields::create( array(
'type' => 'text',
'id' => 1003, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => 'Middle Name (optional)',
'pageNumber' =>; 2, // Ensure this is correct
) );
// Create a Single Line text field for the family member's last name
$FamilyLastName = GF_Fields::create( array(
'type' => 'text',
'id' => 1004, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => 'Last Name',
'pageNumber' => 2, // Ensure this is correct
) );
// Create a Single Line text field for the family member's relationship to you
$FamilyRelationship = GF_Fields::create( array(
'type' => 'text',
'id' => 1005, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => 'Relationship to You',
'pageNumber' => 2, // Ensure this is correct
) );
// Create a Date field for the family member's date of birth
$FamilyDateOfBirth = GF_Fields::create( array(
'type' => 'date',
'dateType' => 'datefield',
'dateFormat' => 'dd/mm/yyyy',
'id' => 1006, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => 'Date of Birth',
'pageNumber' => 2, // Ensure this is correct
) );
// Create a repeater for the team members and add the name and email fields as the fields to display inside the repeater.
$family = GF_Fields::create( array(
'type' => 'repeater',
'description' => 'Maximum of 9 family members - set by the maxItems property',
'id' => 1000, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => 'Family Members',
'addButtonText' => 'Add team member', // Optional
'removeButtonText' => 'Remove team member', // Optional
'maxItems' => 9, // Optional
'pageNumber' => 2, // Ensure this is correct
'fields' => array( $FamilyFirstName, $FamilyMiddleName, $FamilyLastName, $FamilyRelationship, $FamilyDateOfBirth ), // Add the fields here.
) );
$form['fields'][] = $family;
return $form;
}
// Remove the field before the form is saved. Adjust your form ID
add_filter( 'gform_form_update_meta_2', 'remove_my_field', 10, 3 );
function remove_my_field( $form_meta, $form_id, $meta_name ) {
if ( $meta_name == 'display_meta' ) {
// Remove the Repeater field: ID 1000
$form_meta['fields'] = wp_list_filter( $form_meta['fields'], array( 'id' => 1000 ), 'NOT' );
}
return $form_meta;}
The multi-page form can be started at https://servefoundationcom.wpcomstaging.com/apply/. The part where the code is supposed to working is at https://servefoundationcom.wpcomstaging.com/apply/#gf_2