Dynamic population checkbox plus removing/unset default checkbox value

I have a field with two checkboxes: Value 1 and value 2. I use the Dynamic Population feature and set the second checkbox (value) as checked by including the parameter in the URL (i.e. domain.com/?checkboxgroup=value2).

However, in the form, the first checkbox is enabled by default and I want to disable it.

Is it possible to deactivate the first checkbox (also via ‘dynamic population’)?

Or is it better to set the first checkbox not enabled and enable both checkboxes with the dynamic population feature?

Thanks for your help.

If you want to clear the defaults when dynamic population is used you can use the gform_pre_render filter in the theme functions.php file, in a custom plugin, or with a code snippets plugin e.g.

add_filter( 'gform_pre_render', function ( $form, $ajax, $field_values ) {
	if ( empty( $form['id'] ) ) {
		return $form;
	}

	foreach ( $form['fields'] as $field ) {

		if ( ! $field instanceof GF_Field_Checkbox || ! $field->allowsPrepopulate || empty( $field->inputName ) ) {
			continue;
		}

		$value = GFFormsModel::get_parameter_value( $field->inputName, $field_values, $field );
		if ( rgblank( $value ) ) {
			continue;
		}

		$field->defaultValue = '';

		foreach ( $field->choices as &$choice ) {
			$choice['isSelected'] = false;
		}
	}

	return $form;
}, 10, 3 );

Great, but can I specify which default field/value should be reset/unset by using the field ID or something like that?

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