0

I've created a form for my plugin settings and set the action attribute of the form to "options.php" but when I submit the form I get "ERROR: options page not found."

add_action('admin_menu', 'create_menu');

function create_menu(){
    // add menu page
    add_menu_page(
        'Basic Plugin Menu Page', 
        'Bp Menu', 
        'manage_options', 
        'bp_menu', 
        'bp_menu_cb', 
        plugins_url('images/wordpress.png', __FILE__),
        76 );
    // add submenu page
    add_submenu_page(
        'bp_menu', 
        'Besic Plugin Submenu', 
        'Options', 
        'manage_options', 
        'bp_options', 
        'bp_options_cb' );
    add_action('admin_init', 'bp_register_settings_cb');
} // end add_menu
function bp_register_settings_cb(){
    // - register_setting( $option_group, $option_name, $sanitize_callback );
    register_setting('bp-settings-group', 'bp_options', 'bp_options_sanitize');
} // enb bp_register_settings_cb

function bp_options_sanitize($input){
    $input['name'] = sanitize_text_field($input['name']);
    $input['email'] = sanitize_email($input['email']);
    $input['url'] = esc_url($input['url']);
    return $input;
} // end bp_options_sanitize

function bp_menu_cb(){ ?>
    <div id="wrap">
        <h2>Basic Plugin Settings</h2>
        <form method="POST" action="http://localhost/blogger.allaudin/wp-admin/options.php">
            <?php settings_fields('bp_settings_group'); ?>
            <?php $bp_options = get_option('bp_options') ?>
            <table class="form-table">
                <tr valign="top">
                    <th scope="row">Name</th>
                    <td>
                        <input type="text" name="bp_options[name]" value="<?php echo esc_attr($bp_options['name']) ?>" />
                    </td>
                </tr>
                <tr valign="top">
                    <th scope="row">Email</th>
                    <td>
                        <input type="text" name="bp_options[email]" value="<?php echo esc_attr($bp_options['email']); ?>" />
                    </td>
                </tr>

                <tr valign="top">
                    <th scope="row">URL</th>
                    <td>
                        <input type="text" name="bp_options[url]" value="<?php echo esc_url($bp_options['url']) ?>" />
                    </td>
                </tr>
            </table>
            <p class="submit">
                <input type="submit" class="button-primary" value="Save Changes" />
            </p>
        </form>
    </div>
<?php } // end bp_settings_page
  • In the function bp_menu_cb(), you have used settings_fields('bp_settings_group'); but it should be settings_fields('bp-settings-group'); because in the function bp_register_settings_cb() you have used "bp-settings-group" and not "bp_settings_group" – WisdmLabs Sep 21 '15 at 7:57
5

settings_fields('bp_settings_group');

bp_settings_group should be changed to bp-settings-group to match.

settings_fields( $option_group )

$option_group should match the group name used in register_setting() i.e bp-settings-group.

check on codex here.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.