In my plugin settings page, I have a list of checkboxes that store the value into an array. While the it works as expected, whenever I uncheck all of the checkboxes and save those changes I get the following error:
Notice: Undefined index: remove_field in ...\settings-profile.php on line 19
Below is the code in question:
if ( isset( $_POST['dsbl_options'] ) && !empty( $_POST['dsbl_options'] ) ) {
update_option( 'dsbl_remove', $_POST['remove_field'] ); // (Line 19)
}
The rest of the source code can be found here: GitHub
From doing research online for a similar error, I see that the recommendation is to wrap $_POST['remove_field']
with an isset
. However, this does not store the values form the checkboxes in the plugin settings.
As mentioned above, this error shows up only when all of the checkboxes are unchecked and saved. It looks like there is an issue when saving an empty value in the array. Although the plugin settings works as expected, I'd like to fix this.
$_POST['remove_field']
to avoid trying to use it if it's empty.$_POST['remove_field']
?$_POST['dsbl_option']
but you are not testing if$_POST['remove_field']
has a value before you use it. If you can post more of your code, I could post a full answer for you. As it is, I do not know what dsbl_option or 'remove_field' refer to.