Checkbox values not saved when using repeater field

I’m using a repeating field created from the fields on another form using the following code. The problem is that when using a checkbox in a repeater field the values are not saved after submitting the form.

I am using the same method to add repeater fields to other forms and it’s working fine for all of the other fields I have tested. I was looking for alternative fields but there was nothing that allows multiple selections that also works well with touchscreens.

The plugin version is 2.5.9.2 and WP 5.8

add_filter( 'gform_form_post_get_meta_3', 'add_risk_asses_risks_form' );

function add_risk_asses_risks_form( $form ) {

	$field_id = 1000;
    $repeater = GF_Fields::create( array(
        'type'       		=> 'repeater',
        'id'         		=> $field_id,
        'formId'     		=> $form['id'],
        'addButtonText'    	=> __( 'Add risk', 'theme-prefix' ),
        'removeButtonText' 	=> __( 'Remove risk', 'theme-prefix' ),
        'pageNumber' => 1, // Ensure this is correct
    ) );
 	
	
    $another_form = GFAPI::get_form( 4);
    foreach ( $another_form['fields'] as $field ) {
        $field->id         = $field->id + $field_id;
        $field->formId     = $form['id'];
        $field->pageNumber = 1; // Ensure this is correct
 
            if ( is_array( $field->inputs ) ) {
            foreach ( $field->inputs as $input ) {
                $input['id'] = (string) ( $input['id'] + $field_id );
            }
        }  
    }
 
    $repeater->fields = $another_form['fields'];
	
	$repeater_exists = false;
      foreach ( $form['fields'] as $field ) {
        if ( 'repeater' === $field->type && $field->id === $field_id ) {
          $repeater_exists = true;
        }
      }
      if ( ! $repeater_exists ) {
        $form['fields'][] = $repeater;
      }
      return $form; 
}

Hi Liam. For the checkbox field in form 4, are the choices unique or if you are using values, are the values unique?

Yes, they are all unique and I am not using the option to change the value separately. I decided to try and remake the repeater form but it did not seem to change anything.

I am going to try a fresh install and see how that goes, although the site I am working on has very few plugins or code added that might break something. I have 6 other forms, some with multiple repeaters and they all seem to be working fine apart from this one checkbox field.

The values I am using are:
Employees
Subcontractor
General public
Young persons
Visitors
Operational plant

I have tested again with a fresh install and the same thing happens. The test has a few random fields added to each form, as well as a checkbox on the form to be used as the repeater and when viewing the entries that is the only thing without a value.

I’ve been working on other things and had not got around to testing properly, but the entries from when I initially made it does have values for the checkbox. The site is only a couple of months old at best and the plugin has had a couple of updates so I think it must be a bug introduced in one of the more recent releases.

Hi Liam. I recommend opening a support ticket for this issue if you have not already:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.