[wp-hackers] Saving Radio Options in Plugin Menu
Otto
otto at ottodestruct.com
Sat Nov 23 11:36:43 UTC 2013
On Sat, Nov 23, 2013 at 5:23 AM, BenderisGreat <greglancaster71 at gmail.com>wrote:
> The whole block is wrong?
Oh, yes. What is the output from that?
printf(
'<input id="%s" type="radio" name="ams_options[%s]"
value="voteThumbs">voteThumbs', 'ams_choose_comment_buttons', checked(
'voteThumbs' == $buttonStyle ));
The output from that looks like it would probably be the following:
checked='checked'<input id="ams_choose_comment_buttons" type="radio"
name="ams_options[]" value="voteThumbs">voteThumbs
Which simply doesn't make any sort of rational sense.
This is how you would do that correctly. For one, you wouldn't use a printf
at all:
<input type="radio" name="ams_options[ams_choose_comment_buttons]"
value="voteThumbs"
<?php checked($buttonStyle, 'voteThumbs') ?>>voteThumbs</input>
The important things here are:
- No duplicated ID fields. IDs have to be unique across the whole HTML
document. If you want to give them an ID, that's fine, but they cannot all
be the same.
- The "name" must make sense. Sticking the output of the "checked" field
into it makes no sense.
- The "checked" function makes output on its own, calling it as a parameter
inside a printf makes no sense
- You don't need an == check inside the checked() function call.
- The checked function call needs to be made inside the <input> html,
because it's outputting an attribute
-Otto
More information about the wp-hackers
mailing list