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.

Processing the following form in the admin area, but the database constantly returning an empty cell where the info should be. Help!!

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

            <input type="hidden" value="admin_bar" name="option_page"><input type="hidden" value="update" name="action"><input type="hidden" value="fd5754f034" name="_wpnonce" id="_wpnonce"><input type="hidden" value="/accessibilitysite/wp-admin/options-general.php?page=admin_bar&amp;settings-updated=true" name="_wp_http_referer">


            <table class="form-table">


        <tbody><tr valign="top"><th scope="row">Admin Toggle</th>
                                <td><input type="checkbox" value="admin_bar_toggle" name="admin_bar_[admin_bar_toggle]"><p>Turn Admin Bar On ?</p></td>

        </tr>   

            </tbody></table>

            <p class="submit">

            <input type="submit" value="Save Changes" class="button-primary">

            </p>

        </form>
share|improve this question
    
Errmm.... value=""? Checkboxes still need a value. –  t31os Mar 30 '11 at 15:54
    
sorry, silly mistake. It's still not saving anything useful. I know this is rookie. Sorry –  Mild Fuzz Mar 30 '11 at 16:05
    
As Andy has pointed out, unless the option is whitelisted, options.php won't save your data, typically the easiest way to whitelist an option(or set of options) is using register_setting, without that though your option doesn't make it past the whitelist. Andy has provided a solution for you though... :) –  t31os Mar 30 '11 at 16:39
    
Silly HTML error. The problem was having a value. Removing it allowed the code to save the string "on" when the checkbox was ticked, and I can build my logic around that. –  Mild Fuzz Mar 31 '11 at 10:31

1 Answer 1

up vote 2 down vote accepted

options.php does not automatically save in the database anything that you post to it. You must also tell the page which options it should look for in the posted data.

I see that you have set option_page to admin_bar, which is half of the solution. The other half is to add the option names to the whitelist. You are using the form element name admin_bar_[admin_bar_toggle] which will show up as $_POST['admin_bar_']['admin_bar_toggle'] when the form is submitted with that box checked. This filter should tell options.php that you want this option saved:

function admin_page_whitelist_options( $whitelist_options ) {
    $whitelist_options['admin_bar'] = array( 'admin_bar_' );
    return $whitelist_options;
}
add_filter( 'whitelist_options', 'admin_page_whitelist_options' );

After that, you should find what you are looking for in the option named admin_bar_.

share|improve this answer
    
t31os correctly points to register_setting, which is part of a relatively new API described here: codex.wordpress.org/Settings_API –  Andy Mar 30 '11 at 16:51
1  
You may also find this tutorial useful: chipbennett.net/2011/02/17/… –  Chip Bennett Mar 30 '11 at 19:00

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.