1

I’m creating a custom ExpressionEngine extension and I need to add a checkbox. I’m struggling to find the options I need to use for the channel fields API.

Currently I have:

array(
    'field_name' => 'business_for_sale',
    'field_label' => 'Business For Sale?',
    'field_type' => 'checkboxes',
    'field_order' => 25,
    'field_instructions' => 'Is there a business for sale with the commerical property?',
    'field_required' => 'n',
    'field_search' => 'y',
    'field_is_hidden' => 'n',
    'field_list_items' => "Yes",
)

I just want either a single checkbox that will act as a boolean (checked is yes, un-checked is no). Alternatively, I would settle for two radios buttons—one representing Yes and one representing No that the administrator could choose.

2
  • Are you creating an extension, or a fieldtype? Mar 23 '15 at 13:09
  • I’m creating an extension that on activation should create some channel fields, one of which I want to represent a boolean value (“yes” or “no”). Mar 23 '15 at 14:48
0

Native EE checkbox fields simply store the options as plain text - to my knowledge there is no way to make one a true boolean. But what you have should work. The box being left unchecked will result in a NULL value for that field.

So all these should work.

{if business_for_sale == 'Yes'}
{if business_for_sale}
{if business_for_sale == ''}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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