WordPress.org

Ready to get started?Download WordPress

Forums

Adding a reset button and an update message on custom option page? (6 posts)

  1. WSQ
    Member
    Posted 4 years ago #

    I have follow the instruction of the tutorial page
    http://codex.wordpress.org/Creating_Options_Pages
    But however, I just can't insert a (1)reset button and an (2)update message in it.
    Can anyone help me to modify the code?
    Thank you very much.

    <?php
    // create custom plugin settings menu
    add_action('admin_menu', 'baw_create_menu');
    
    function baw_create_menu() {
    
    	//create new top-level menu
    	add_menu_page('BAW Plugin Settings', 'BAW Settings', 'administrator', __FILE__, 'baw_settings_page',plugins_url('/images/icon.png', __FILE__));
    
    	//call register settings function
    	add_action( 'admin_init', 'register_mysettings' );
    }
    
    function register_mysettings() {
    	//register our settings
    	register_setting( 'baw-settings-group', 'new_option_name' );
    	register_setting( 'baw-settings-group', 'some_other_option' );
    	register_setting( 'baw-settings-group', 'option_etc' );
    }
    
    function baw_settings_page() {
    ?>
    <div class="wrap">
    <h2>Your Plugin Name</h2>
    
    <form method="post" action="options.php">
        <?php settings_fields( 'baw-settings-group' ); ?>
        <table class="form-table">
            <tr valign="top">
            <th scope="row">New Option Name</th>
            <td><input type="text" name="new_option_name" value="<?php echo get_option('new_option_name'); ?>" /></td>
            </tr>
    
            <tr valign="top">
            <th scope="row">Some Other Option</th>
            <td><input type="text" name="some_other_option" value="<?php echo get_option('some_other_option'); ?>" /></td>
            </tr>
    
            <tr valign="top">
            <th scope="row">Options, Etc.</th>
            <td><input type="text" name="option_etc" value="<?php echo get_option('option_etc'); ?>" /></td>
            </tr>
        </table>
    
        <p class="submit">
        <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
        </p>
    
    </form>
    </div>
    <?php } ?>
  2. WSQ
    Member
    Posted 4 years ago #

    Can anybody help please?

  3. WSQ
    Member
    Posted 4 years ago #

    just nobody can help?

  4. WSQ
    Member
    Posted 4 years ago #

    ...

  5. hagendit
    Member
    Posted 4 years ago #

    I'm trying to figure this one out too. I've seen lots of instances of people making their own message div echo out before the options form, but this doesn't seem like an elegant solution, and it means you have to process the posted form data yourself.

    I wonder if there is a way to check if options.php updated successfully, and if so, slide an update message in for display?

    Have you managed to find anything further wsqws?

  6. Devin Price
    Member
    Posted 3 years ago #

    On your options page, you can have something like this at the top:

    <?php if ( ! isset( $_REQUEST['updated'] ) )
    		$_REQUEST['updated'] = false;
    	?>
    
    	<div class="wrap">
        <?php screen_icon( 'themes' ); ?>
    	<h2>Theme Options</h2>
    
        <?php if ( false !== $_REQUEST['updated'] ) : ?>
    		<div id="message" class="updated fade"><p><strong><?php _e( 'Options saved' ); ?></strong></p></div>
    	<?php endif; ?>

    Though not sure if it's the best way. The code is currently up at: https://github.com/devinsays/options-framework-plugin

Topic Closed

This topic has been closed to new replies.

About this Topic