Label Association Limits in CakePHP 4.x FormHelper Checkbox and Radio Output
0 reputation · 22 Mar 2020, 20:24 UTC
0 reputation · 22 Mar 2020, 20:24 UTC
CakePHP 4.x projects commonly render entire form fields through FormHelper::control(), and accessibility targets such as WCAG 2.1 AA require every control to have a programmatic label and, where needed, a supporting description. The documented options array accepts attributes like aria-label and aria-describedby, but it is not obvious how much label association the helper performs on its own for checkbox and radio inputs versus what must be configured field by field.
The same uncertainty applies to navigation. Teams need to know whether PaginationHelper emits landmark markup and accessible controls by default, or whether template customization is the only route to compliant pagination. Deciding between per-control options and centralized template overrides depends on where the built-in support actually ends.
Where does default support stop for checkbox and radio label association in CakePHP 4.x, and is the label option required for each control to achieve proper association? Are ARIA attributes passed through the options array rendered directly on the generated input elements? Does PaginationHelper provide a navigation landmark and accessible labels without custom templates?
33775 reputation · 23 Mar 2020, 02:55 UTC
In CakePHP 4.x, FormHelper::control() provides automatic programmatic label association for checkboxes and radio buttons. By default, the helper generates a <label> element with a for attribute that matches the id of the generated input. This satisfies basic WCAG requirements for programmatic association without requiring a manual label option for every field.
label option is omitted, CakePHP derives the label text from the field name. The programmatic link (for attribute) remains intact.label Option: Setting 'label' => false removes the <label> element entirely. In this scenario, you must provide an aria-label or aria-labelledby to maintain accessibility.aria-describedby, aria-required) passed within the options array are rendered directly onto the resulting <input> element.The PaginationHelper does not provide a navigation landmark (such as the <nav> element) or ARIA labels by default. It generates the necessary pagination links and numbers, but the semantic wrapping required for WCAG 2.1 AA compliance is absent from the standard templates.
Because the helper stops at generating the link list, template customization is the only route to compliant pagination. You must wrap the helper output in a landmark element manually in your template file:
<nav aria-label="Page navigation">
Paginator->numbers() ?>
Paginator->prev() ?>
Paginator->next() ?>
</nav>
To verify the current behavior in your specific 4.x version, perform the following checks:
control() and verify the <label for="..."> matches the <input id="...">.['aria-describedby' => 'help-text'] into the options array and confirm the attribute appears on the input tag.<nav> tag is missing, template overrides are required.Diagnostic Note: Are you using a custom FormHelper wrapper or a specific UI plugin (like CakePHP-Bootstrap)? These often override default template behaviors and may change how labels are nested.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.