admin管理员组文章数量:1023070
I have a php form that I want to change the state of a checkbox so it's filled by default, but there are two fields that may be the right way:
'request_vendor_access' => array(
'label' => __( 'Request access to become an Artist', 'ignitewoo_vendor_stores' ),
'type' => 'checkbox',
'required' => false,
'class' => array( 'form-row-full vendor_stores_request_access' ),
'clear' => true,
'default' => 'go',
),
I would have guessed that it would be 'default', but it's set to the string 'go' so perhaps I should set clear
to false
.
What's the correct way to make the checkbox marked by default? Any insight is appreciated.
I have a php form that I want to change the state of a checkbox so it's filled by default, but there are two fields that may be the right way:
'request_vendor_access' => array(
'label' => __( 'Request access to become an Artist', 'ignitewoo_vendor_stores' ),
'type' => 'checkbox',
'required' => false,
'class' => array( 'form-row-full vendor_stores_request_access' ),
'clear' => true,
'default' => 'go',
),
I would have guessed that it would be 'default', but it's set to the string 'go' so perhaps I should set clear
to false
.
What's the correct way to make the checkbox marked by default? Any insight is appreciated.
Share Improve this question asked Apr 17, 2019 at 19:00 JamesJames 1114 bronze badges 5 |1 Answer
Reset to default 0It most likely must is 'default' => TRUE
.
'request_vendor_access' => [
'label' => __('Request access to become an Artist', 'ignitewoo_vendor_stores'),
'type' => 'checkbox',
'required' => FALSE,
'class' => ['form-row-full vendor_stores_request_access'],
'clear' => TRUE,
'default' => TRUE,
]
If not, also try 'default_value' => TRUE,
or try it without 'clear'
.
Depending on what you want to achieve you might also want to get the default value dynamically. So that it restores the user's choice. Maybe get_option($option, $default)
is the right choice here (if that's an Options API form).
'request_vendor_access' => [
'label' => __('Request access to become an Artist', 'ignitewoo_vendor_stores'),
'type' => 'checkbox',
'required' => FALSE,
'class' => ['form-row-full vendor_stores_request_access'],
'clear' => TRUE,
'default' => get_option('request_vendor_access', TRUE),
]
or
'request_vendor_access' => [
'label' => __('Request access to become an Artist', 'ignitewoo_vendor_stores'),
'type' => 'checkbox',
'required' => FALSE,
'class' => ['form-row-full vendor_stores_request_access'],
'clear' => TRUE,
'default' => isset(get_option('my_option')['request_vendor_access'] ? get_option('my_option')['request_vendor_access'] : TRUE,
]
I have a php form that I want to change the state of a checkbox so it's filled by default, but there are two fields that may be the right way:
'request_vendor_access' => array(
'label' => __( 'Request access to become an Artist', 'ignitewoo_vendor_stores' ),
'type' => 'checkbox',
'required' => false,
'class' => array( 'form-row-full vendor_stores_request_access' ),
'clear' => true,
'default' => 'go',
),
I would have guessed that it would be 'default', but it's set to the string 'go' so perhaps I should set clear
to false
.
What's the correct way to make the checkbox marked by default? Any insight is appreciated.
I have a php form that I want to change the state of a checkbox so it's filled by default, but there are two fields that may be the right way:
'request_vendor_access' => array(
'label' => __( 'Request access to become an Artist', 'ignitewoo_vendor_stores' ),
'type' => 'checkbox',
'required' => false,
'class' => array( 'form-row-full vendor_stores_request_access' ),
'clear' => true,
'default' => 'go',
),
I would have guessed that it would be 'default', but it's set to the string 'go' so perhaps I should set clear
to false
.
What's the correct way to make the checkbox marked by default? Any insight is appreciated.
Share Improve this question asked Apr 17, 2019 at 19:00 JamesJames 1114 bronze badges 5-
Of course you have tried
TRUE
and'checked'
already, have you? – norman.lol Commented Apr 17, 2019 at 19:16 -
checked
works in the html but I need to change it in the php file instead. Where would you recommend I addTRUE
? – James Commented Apr 17, 2019 at 19:21 -
1
'default' => TRUE
. In Drupal it's'default_value' => TRUE
. And remove'clear' => TRUE'
. – norman.lol Commented Apr 17, 2019 at 19:41 -
Yes it is definitively
'default' => true
or'default' => '1'
– LoicTheAztec Commented Apr 18, 2019 at 0:32 - 1 Don't edit plugin files. You'll lose your changes if/when it's updated. Check the plugin docs or contact its author to find out the supported way to change this behaviour. – Jacob Peattie Commented Apr 18, 2019 at 7:06
1 Answer
Reset to default 0It most likely must is 'default' => TRUE
.
'request_vendor_access' => [
'label' => __('Request access to become an Artist', 'ignitewoo_vendor_stores'),
'type' => 'checkbox',
'required' => FALSE,
'class' => ['form-row-full vendor_stores_request_access'],
'clear' => TRUE,
'default' => TRUE,
]
If not, also try 'default_value' => TRUE,
or try it without 'clear'
.
Depending on what you want to achieve you might also want to get the default value dynamically. So that it restores the user's choice. Maybe get_option($option, $default)
is the right choice here (if that's an Options API form).
'request_vendor_access' => [
'label' => __('Request access to become an Artist', 'ignitewoo_vendor_stores'),
'type' => 'checkbox',
'required' => FALSE,
'class' => ['form-row-full vendor_stores_request_access'],
'clear' => TRUE,
'default' => get_option('request_vendor_access', TRUE),
]
or
'request_vendor_access' => [
'label' => __('Request access to become an Artist', 'ignitewoo_vendor_stores'),
'type' => 'checkbox',
'required' => FALSE,
'class' => ['form-row-full vendor_stores_request_access'],
'clear' => TRUE,
'default' => isset(get_option('my_option')['request_vendor_access'] ? get_option('my_option')['request_vendor_access'] : TRUE,
]
本文标签: phpWhich field should I edit to make the checkbox marked by default
版权声明:本文标题:php - Which field should I edit to make the checkbox marked by default? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745577924a2157133.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
TRUE
and'checked'
already, have you? – norman.lol Commented Apr 17, 2019 at 19:16checked
works in the html but I need to change it in the php file instead. Where would you recommend I addTRUE
? – James Commented Apr 17, 2019 at 19:21'default' => TRUE
. In Drupal it's'default_value' => TRUE
. And remove'clear' => TRUE'
. – norman.lol Commented Apr 17, 2019 at 19:41'default' => true
or'default' => '1'
– LoicTheAztec Commented Apr 18, 2019 at 0:32