I’mt trying to create a plugin which adds a custom page in the admin panel. I have a checkbox with name “deposit_sandbox” if check true it should update the option in the database to true, if not selected it should update the option in the database to false.
how do I check if a checkbox was selected and then update the database with update_option() function?
It works if I leave the action blank and then use $_POST, but I would need to do this for each item in my form. if there is a workaround please let me know 🙂
If your options have the same name as the checkboxes, you can write the following:
I don’t remember if update_option accepts boolean values (like
$checkedin my example). If it doesn’t, change the$checkedline for$checked = isset($_POST["deposit_sandbox"]) ? 1 : 0;.I’m supposing you create default values to all your options when you activate the plugin.