Saving checkbox/option list status?

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:

Read More
<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?

Related posts

Leave a Reply

2 comments

  1. This is really just an html question, not specific to WordPress. Look into checked="checked" (for check boxes) or selected="selected" (for selects, radio buttons, etc.) In your case,

    <input type="checkbox" name="showS" value="true" 
        <?php if (get_option('showS')==true) echo 'checked="checked" '; ?>>
    

    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/