• Hello everyone! I’m actually trying to build an option page for my plugin, with only 2 checkboxes.

    I use this code to register the 2 settings:

    register_setting( 'at_options_group', 'at_option_use_taxarchive');
    register_setting( 'at_options_group', 'at_option_show_taxmenu');

    And this code to generate the option page:

    <div class="wrap">
    <form method="post" action="options.php">
    <?php settings_fields( 'at_options_group' ); ?>
    <?php do_settings_fields( 'at_setting', 'at_options_group' ); ?>
    <table class="form-table">
            <tr valign="top">
            <th scope="row">My first option title</th>
            <td>
    	<input type="checkbox" name="at_option_use_taxarchive" <?php if ( 1 == 'at_option_use_taxarchive' ) echo 'checked="checked"'; ?> /></td></tr>
            <tr valign="top">
            <th scope="row">My second option title</th>
            <td><input type="checkbox" name="at_option_show_taxmenu" <?php if ( 1 == 'at_option_show_taxmenu' ) echo 'checked="checked"'; ?> /></td>
            </tr>
        </table>
    <?php submit_button(); ?>
    </form>
    </div>

    But when i save, nothing changes in my page ??
    Any help would be appreciate
    Thanks in advance!

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

    (@bcworkz)

    The register_setting() functions should be called from the action hook ‘admin_init’. See the example at Function_Reference/register_setting#Example.

    The Settings API is normally used to add fields to existing pages. You do not define your own form or else the API may not know how to handle your settings. You can add your own Administration Menus if you do not want to use existing pages. Then you can add sections and fields to your newly defined menu page via the API. This way, the form and saving and populating fields is handled semi-automatically.

    Moderator bcworkz

    (@bcworkz)

    Err, about the not defining your own form… never mind. You do for a new options page. It’s been a while since I’ve added a new page, I’d forgotten that I defined a form at that time. However, the form does not have the actual fields, it’s basically just this for API usage:

    <form method="post" action="options.php">
    <?php settings_fields('page-slug');
    do_settings_sections('page-slug');
    submit_button(); ?>
    </form>

    Ugh! Another bit of bad info about the API populating the fields, it doesn’t. You use get_option() in the callback specified when you add the field through the API.

    Sorry about the faulty details, but the main point holds true, use the Settings API to build the contents of your options page and the settings will be saved automatically for you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Cannot save checkboxes values in option page’ is closed to new replies.