PhotoDune

Saving options in a theme options panel, instant "update"

947 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Ireland
  • Sold between 10 000 and 50 000 dollars
EireStudio says

Hey Guys,

I am saving some options into my “theme options panel” if you can call it that but when I add/update let’s say an input box it adds/updates fine but I have to refresh again for the correct value to be shown, how do I instantly show the value/new value? :)

2507 posts Put a Donk On It
  • Attended a Community Meetup
  • Beta Tester
  • Bought between 10 and 49 items
  • Contributed a Tutorial to a Tuts+ Site
  • Elite Author
  • Exclusive Author
  • Has been a member for 3-4 years
  • Interviewed on the Envato Notes blog
+5 more
ThemeProvince says

Learn Ajax I suppose :)

750 posts
  • Author had a Free File of the Month
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 10 000 and 50 000 dollars
AdamGold says
You probably use get_option() to retrieve the values in the input fields. You should do something like this:
if( $_REQUEST ) {
extract($_REQUEST);
} else {
// Use what you use now, get_option()
}

Then enter the right variable inside the values of the fields.

947 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Ireland
  • Sold between 10 000 and 50 000 dollars
EireStudio says

@Phoenix, not that fast of an update, just a standard refresh :)

Here is my code:

Be prepared for extremely rough code, no under 18s! :)

 <?php echo $eirepanel_general_options = get_option('eirepanel_general_options');
            echo $general_settings_saved = $_REQUEST['general-settings'];
            if(isset($general_settings_saved))
            { 
                header("Location: http://www.google.com"); 
                echo 'Yes it is saved';

            }

            ?>

            <?php // echo 'SET';
                update_option('eirepanel_general_options', $_POST['eirepanel_general_options']);
                header("Location: admin.php?page=eirepane-sidebars#test"); 

            ?>
                <form method="post" action="#general-settings?saved=true">
                    <input name="general-settings" value="true" type="hidden" />
                    Text String <input name="eirepanel_general_options" value="<?php echo $eirepanel_general_options; ?>" type="text" />
                    <input name="submit" value="Save" type="submit" />
                </form>

    <?php }

</pr?>
750 posts
  • Author had a Free File of the Month
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 10 000 and 50 000 dollars
AdamGold says
You don’t need to echo anything when you define a variable.
 <?php $eirepanel_general_options = ( (isset($_REQUEST)) ? $_REQUEST['eirepanel_general_options'] : get_option('eirepanel_general_options') );
 $general_settings_saved = $_REQUEST['general-settings'];
            if(isset($general_settings_saved))
            { 
                header("Location: http://www.google.com"); 
                echo 'Yes it is saved';

            }

            ?>

            <?php // echo 'SET';
                update_option('eirepanel_general_options', $_POST['eirepanel_general_options']);
                header("Location: admin.php?page=eirepane-sidebars#test"); 

            ?>
                <form method="post" action="#general-settings?saved=true">
                    <input name="general-settings" type="hidden" value="true" />
                    Text String <input name="eirepanel_general_options" type="text" value="<?php echo $eirepanel_general_options; ?>" />
                    <input name="submit" type="submit" value="Save" />
                </form>

    <?php }
</pr?>
947 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Ireland
  • Sold between 10 000 and 50 000 dollars
EireStudio says

Perfect!!

Thanks a million Adam, really appreciate it mate!


You don’t need to echo anything when you define a variable.
 <?php $eirepanel_general_options = ( (isset($_REQUEST)) ? $_REQUEST['eirepanel_general_options'] : get_option('eirepanel_general_options') );
 $general_settings_saved = $_REQUEST['general-settings'];
            if(isset($general_settings_saved))
            { 
                header("Location: http://www.google.com"); 
                echo 'Yes it is saved';

            }

            ?>

            <?php // echo 'SET';
                update_option('eirepanel_general_options', $_POST['eirepanel_general_options']);
                header("Location: admin.php?page=eirepane-sidebars#test"); 

            ?>
                
Text String <?php } </pr?>
by
by
by
by
by