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;
}