0

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 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!

  • You can use hidden inputs for this. On the other hand, you've to store and get the defaults from somewhere in your plugin anyway. If they never change, it might not make a lot of sense to save them with the form in the first place. In the end it is a question of what makes logically the most sense in your specific case. – Nicolai Jul 10 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.