Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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/

share|improve this answer
    
To be honest I don't know HOW to use Settings on my wordpress admin pages, the link you gave me is the only one live example of that function but it's for a plug, not admin page and I couldn't force it to work for me. I've been everywhere from Codex to that particular page and never found settings well explained. –  Wordpressor Jan 11 '11 at 16:57
    
Maybe its time for a simpler tutorial on the process, then? I can't think of any offhand... the chapter on plugin development in Professional WordPress was helpful to me. But if I find a simpler tutorial, I'll try to remember to come back and post it. Or - better - work through it as far as you can and ask questions here when you get stuck... –  goldenapples Jan 11 '11 at 17:14
3  
There are couple great WP functions for shorthand checked() and selected() checks, highly recommend over writing it out. :) –  Rarst Jan 11 '11 at 19:13
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.