• Resolved Michael

    (@mikeyhoward1977)


    I want to change my plugin’s custom settings page to be tabbed. I have added the necessary code and the appearance is all fine.

    However, I do not want to change the way in which my settings are saved to the wp_options table – currently these settings are saved to a single field.

    Question is, even with a number of tabs on my settings page, can all the settings still be saved to the same field or must I now have multiple fields – i.e. 1 per tab?

    As it stands now, if I save the settings displayed on tab 1, the other settings are all removed from the DB.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes you can save all tabs in a single field, but all the tabs must be populated with the current values so they can all be saved back into the DB on any one tab save. This means all tabs must be all part of a single form on a single page, regardless on how it appears in the browser. When the user saves a particular tab, they are in fact saving all the tabs at once.

    Alternately, an AJAX handler could be set up that understands the option field data structure and only updates the values from the current tab, leaving the other data unchanged. In this scenario, while a single field is possible, it would be much easier to have an options field for each tab.

    If you have more questions, it would be useful to know how you are saving the data now, or are you using the Settings API?

    Dion

    (@diondesigns)

    It will take some work, but you can use type="hidden" INPUT tags to define the settings that aren’t on the page. For example:

    $settings = get_option('mysettings');
    echo '<form>
    	(your form)
    	<input type="hidden" name="mysettings[hiddenoption]" value="' . esc_attr($settings['hiddenoption']) . '" />
    </form>';

    Using a single option for multiple tabs is a maintenance nightmare. I know you said you didn’t want to create options for each tab, but it is the best solution, and it’s something you should consider.

    Thread Starter Michael

    (@mikeyhoward1977)

    Thanks guys. As suggested I opted to create multiple options in the DB – 1 for each tab.

    I did try the hidden input field option but did not have much joy and to be honest it was getting a little messy.

    Thanks for your help, much appreciated

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Saving Plugin options on tabbed settings screen’ is closed to new replies.