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.

I have a form that looks as such:

<form action="options.php" method="post">
  <ul class="nav nav-tabs">
    <li>
      <a href="#content" data-toggle="tab">content</a>
    </li>
    <li>
      <a href="#contentversion2" data-toggle="tab">content version 2</a>
    </li>
  </ul>
  <div class="tab-content">
    <div class="tab-pane active" id="content">
      <div class="controls">
        <input type="url" name="aisis_core[index_more_posts]" placeholder="Url" />
      </div>
      <div class="form-actions">
        <input type="submit" value="Submit" />
      </div>
    </div>
    <div class="tab-pane" id="contentversion2">
      content for this tab as well
    </div>
  </div><input type="hidden" name="option_page" value="aisis_options" /><input type=
  "hidden" name="action" value="update" /><input type="hidden" id="_wpnonce" name=
  "_wpnonce" value="0360d57793" /><input type="hidden" name="_wp_http_referer" value=
  "/wordpress/wp-admin/admin.php?page=aisis-core-options&amp;settings-updated=true" />
</form>

The problem is, when I hit submit, the following options validator function is then called, based on the registered settings:

public function option_validator($input){
    var_dump($input); exit;
    $option = get_option('aitisis_core');
    $option = $input;
    update_option('success_message', true);
    return $option;
}

The problem as you can see from the var dump is that the input is always null....no matter what I put into the url input.

I registered the setting as such:

public function settings(){
    register_setting(
        'aisis_options', 
        'aisis_options', 
        array(
            $this, 
            'option_validator'
        )
    );
}

any tips?

share|improve this question

1 Answer 1

This kind of setup skeleton works for me to process the custom options page input :

<?php
/*
Plugin Name: Settings Skeleton
*/

if(!class_exists('MySettings')){    

    function call_my_settings() {
        return new MySettings();
    }

    if (is_admin()){
        add_action( 'init', 'call_my_settings' );
    }

    class MySettings{

        public function __construct(){
            add_action('admin_menu', array(&$this, 'add_menu'));
            add_action('admin_init', array(&$this,'settings') );
        }

        public function add_menu(){
            add_options_page(__('My Plugin Settings','myplugindomain'), 'My Plugin Settings', 'manage_options', __FILE__,  array(&$this,'options_page'));
        }   

        public function settings() {
            register_setting( 'my_settings', 'my_settings', array(&$this,'validate') );
        }

        public function validate($input) {
            // do validation
            $input['mytext']=esc_attr($input['mytext']);
            return $input;
        }

        public function options_page(){
        ?>
        <div class="wrap">
            <div class="icon32" id="icon-options-general"><br></div>
            <h2><?php _e('My plugin settings','myplugindomain'); ?></h2>
            <form method="post" action="options.php">
                <?php settings_fields('my_settings'); ?>
                <?php $settings = get_option('my_settings'); ?>
                <table class="form-table">
                    <tr>
                        <th scope="row" colspan="2">
                            <h3><?php _e('General settings','myplugindomain'); ?></h3>
                        </th>
                    </tr>
                    <tr>
                        <th scope="row"><?php _e('My text','myplugindomain'); ?> </th>
                            <td>
                                <input type="text" size="70" name="my_settings[mytext]" value="<?php echo $settings[mytext]; ?>" />
                             </td>
                     </tr>
                </table>
                <?php submit_button(); ?>
             </form>
         </div>
        <?php
        }
    }
}

This will give you the following options page:

settings menu

settings

How do you hook your settings() function ?

In the code example above the settings() functions is hooked into the admin_init action, i.e.

add_action('admin_init', array(&$this,'settings') );
share|improve this answer

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.