I have created a page for plugin. For that page i have added a checkbox meta field. The field is working fine. By default, the checkbox field is unchecked. I mean at first to active the plugin, the checkbox field is unchecked. But I need to make it check by default. I have tried a condition but not working at all. My code is :
function ins_street_address_shortcode_callback(){
$val = get_option('ins_street_address_shortcode');
$checkval = "";
if ($val == 'on'){
$checkval = "checked";
}
printf("<input type='checkbox' name='ins_street_address_shortcode' %s />", $checkval);
}
I have created a page for plugin. For that page i have added a checkbox meta field. The field is working fine. By default, the checkbox field is unchecked. I mean at first to active the plugin, the checkbox field is unchecked. But I need to make it check by default. I have tried a condition but not working at all. My code is :
function ins_street_address_shortcode_callback(){
$val = get_option('ins_street_address_shortcode');
$checkval = "";
if ($val == 'on'){
$checkval = "checked";
}
printf("<input type='checkbox' name='ins_street_address_shortcode' %s />", $checkval);
}
Share
Improve this question
edited Jun 23, 2019 at 10:42
Camille V.
3391 gold badge2 silver badges12 bronze badges
asked Jun 23, 2019 at 3:14
BinsaifullahBinsaifullah
111 bronze badge
2 Answers
Reset to default 2Actually, your code is working, as long as $val == 'on'
.
Did you try debugging by doing echo $val
?
If it's still not working, try hard refreshing (Ctrl + F5) your webpage, checkboxes tend to keep their state on normal refresh (F5).
Also, please put your code directly on this forum, so the code is always accessible for future viewers ;)
If you want a HTML checkbox to be checked by default just add "checked" attribute:
printf("<input type='checkbox' name='ins_street_address_shortcode' %s /> checked", $checkval);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745376714a4625033.html
评论列表(0条)