• I’m updating a option page for my theme to use settings_fields and post to options.php

    The code works and the option is save to the wp_options table, but I do not get a confirmation message back.
    Example: <div id=”message” class=”updated”>Setting Saved</div>

    Here is the code:

    function swc_form_init ()
    {
    	register_setting('swc_form_options', 'swc_theme_color_selection', );
    }
    add_action('admin_init','swc_form_init');
    
    //  theme color options
    function swc_theme_color_page() {
    	?>
    <div class="wrap"><?php screen_icon(); ?>
    <h2>Theme Color</h2>
    <form action="options.php" method="post" id="swc-theme-color-form">
    <?php settings_fields('swc_form_options');  ?>
    <h3><label for="swc_theme_color_selection">Enter you color option</label>
    <input type="text" id="swc_theme_color_selection" name="swc_theme_color_selection" value="<?php echo esc_attr(get_option('swc_theme_color_selection')); ?>" /></h3>
    <p><input type="submit" name="submit" value="Save Selection" /></p>
    </form>
    </div>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try:

    <div class="wrap"><?php screen_icon(); ?>
    <h2>Theme Color</h2>
    <?php if ( false !== $_REQUEST['updated'] ) : ?>
    <div class="updated fade"><p><strong><?php _e( 'Your theme options have been saved',); ?></strong></p></div>
    <?php endif; ?>

    Thread Starter simplyworks

    (@simplyworks)

    Thanks esmi,

    I made a slight change once I notice the returning url sends a “updated=true” in the string.

    here is the code that worked for me:

    <div class="wrap"><?php screen_icon(); ?>
    <h2>Theme Color</h2
    <?php if (isset($_GET['updated']) && ($_GET['updated'] == 'true') ) : ?>
    <div class="updated fade"><p><strong><?php _e('Your theme options have been saved'); ?></strong></p></div>
    <?php endif; ?>

    I guess what threw me for a loop, was the fact that if I write this as plugin and not theme option page (the same code) returns a saved message.

    thanks again for the coding tip!

    No problem ??

    I used different codes then above to create a custom page for my theme. It works fine, saves data in wp-options table at Database and shows confirm msg as well.

    PROBLEM:
    When i call (echo) the text contents into the page, it shows blank.

    Can anyone help me pls?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Theme Option Page – register_setting’ is closed to new replies.