Is there a way to preserve values on saving options page

In a plugin, I’ve added an admin page to options menu that contains a form with some inputs. I’ve also added some default values for these inputs stored to the database as an option, on plugin activation. I’ve set some of the default values as defaults to the form inputs.
Some of the default values do not have related inputs. They are used in the form processing.
The problem I cannot solve is that, when I save the entire options page, the defaults that do not have related inputs are lost.

Example:
this is set as default when plugin activated

…..
$my_options = array();
$my_options[‘default_addr’] = “some value”;
$my_options[‘current_num’] = 0;

update_option(‘my_settings’, $my_options);

###################################################
in form processing function:
…..
function my_settings_menu_page_content(){
// a local copy of $my_options
$my_options = get_option( ‘my_settings’ );
…….
<input type=”text” name=”my_settings[default_addr]” id=”my_settings[default_addr]” value=”<?php echo $my_options[‘default_addr’] ; ?>” class=”start-address” />

}

The problem is with $my_options[‘current_num’] = 0;
it is totally lost on form save.

How could I process this value so that its value is preserved accordingly on form save?
Maybe I should add it to the form in some way- a hidden input or something? Any suggestions, if possible?

Best Regards!

Read more here:: Is there a way to preserve values on saving options page

Leave a Reply

Your email address will not be published. Required fields are marked *