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,
]
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745577926a4634078.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