my self-made admin panel works just fine, but it doesn’t save values of form inputs.
When I type something into textbox and click “save” it is still there after refreshing, thanks to PHP:
<input type="text" name="header" value="<?php echo get_option('header'); ?>" />
So the PHP echoes its own value to a input and everything is just fine. But what to do when I have list of 10 radio buttons or just a checkbox?
For now I have a checkbox like this:
<input type="checkbox" name="showS" value="true">
And after clicking on it and saving – it’s still “unclicked”.
Any helping had?
This is really just an html question, not specific to WordPress. Look into
checked="checked"
(for check boxes) orselected="selected"
(for selects, radio buttons, etc.) In your case,Since this is WordPress, though, I should also be reminding you to use the Settings API where possible. Don’t try to sanitize and validate all of the inputs yourself unless you really know what you’re doing. Here’s a link to a tutorial on the Settings API:
http://ottopress.com/2009/wordpress-settings-api-tutorial/
This may be a HTML centric question, but as it happens WordPress does have some helper functions for dealing with checkboxes, select dropdowns, disabled inputs, etc..
http://sillybean.net/2010/09/wordpress-hidden-gems-checked-selected-and-disabled/
Rarst also pointed this out in his comment.
I always use these now, they look more elegant then the self-written alternative methods.