Settings API – Undefined Index when unchecking checkbox

Managed to fix this by doing the following:

function dat_checkbox_field_0_render(  ) { 

    $options = get_option( 'dat_settings' );
    $a = $options;
if (array_key_exists("dat_checkbox_field_0",$a))
  { } else { 
    $options['data_checkbox_field_0'] = false;
  }
    ?>
      <input type="checkbox" name="dat_settings[dat_checkbox_field_0]" <?php checked( $options['dat_checkbox_field_0'], 1 ); ?> value="1">
    <?php

}

Leave a Comment