Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So, I need to add a custom options page, and based on as many tutorials I could find, I came up with the following code to create an officers & chairs options page for my group, mainly, so I can write more advanced stuff for my site. The code is here:

add_action('admin_menu', 'composit_settings_page');

function composit_settings_page()
{
    add_options_page('Officers & Chairs', 'Officers & Chairs', 'manage_options', 'officers_chairs', 'composit_settings');
}

function composit_settings()
{
    $actives = get_users('role=contributor');
    $actives = array_merge($actives, get_users('role=editor'));
    $actives = array_merge($actives, get_users('role=administrator'));


$positions = array(
    "prytanis",
    "epiprytanis",
    "hypophetes",
    "hegemon",
    "grammateus",
    "histor",
    "pylortes",
    "crysopholos"
);

?>
    <div class="wrap">
        <div id="icon-options-general" class="icon32"><br></div>
        <h2>Officers & Chairs</h2>

        <form method="post" action="options.php">
            <?php settings_fields('officers-chairs'); ?>
            <?php foreach($positions as $position):
                    register_setting('officers-chairs', $position, 'intval');
                  endforeach; ?>
            <table class="form-table">
                <tbody>
                    <?php foreach($positions as $position): ?>
                        <tr valign="top">
                            <th scope="row">
                                <label for="<?= $position ?>"><?= ucwords($position) ?></label>
                            </th>
                            <td>
                                <select name="<?= $position ?>" id="<?= $position ?>" class="regular-text">
                                    <?php foreach($actives as $active): ?>
                                        <option value="<?= $active->ID ?>" <?php if(get_option($position) == $active->ID) { ?> selected <? } ?>><?=$active->first_name . " " . $active->last_name ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
            <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes"></p>
        </form>
    </div>
<?
}

However, when I go to save that, I get the following error:

ERROR: options page not found.

I feel completely dumb for not being able to figure this out, but the official documentation hasn't really helped me at all.

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

The problem part is this line:

<form method="post" action="options.php">

This sends your form to wp-admin/options.php (and I guess you're not sending the form from this URL). Lave the action value empty

<form method="post" action="">

And your form will send itself to the same page from which it was sent. Than you can save the settings accessing $_POST variable before outputing

<form method="post" action="options.php">...

Hope this helps...

PS: you should also consider using wordpress nonces. Eg. https://codex.wordpress.org/Function_Reference/wp_nonce_field

share|improve this answer
    
Save settings before output? Know the function off hand?And there is a wpnonce field in there once the page actually outputs. update_option(). We'll see if this works. –  Jeremy Dentel Mar 6 '13 at 16:37
    
Not sure I understand this answer. The options page is defined by a function. You have to run through validation before saving and the saving should be a separate function. –  AlxVallejo Jun 6 '13 at 17:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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