在 Drupal 7 中禁用 webform 中的 required 选项

问题描述

我的功能

     function _custom_get_ublox_communication_checkBox_form_element() {
  return array(
    '#type' => 'checkBoxes','#title' => t('Communications'),'#options' => array(
      1 => t('I consent to retaining my personal data for the purposes of receiving personalized marketing materials,offers,invitations to webinars and other similar events. To learn more,read our <a )),),'#required' => TRUE,);
}

此复选框是强制性的,因为有选项 '#required' => TRUE,但在删除必需选项后,它甚至没有从字段中删除 required(*) 复选框。

解决方法

如果你只想使用一个复选框元素,你应该使用'checkbox'类型而不是'checkboxes'

https://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7.x#checkbox

因此,如果您不需要它,请使用 FALSE 值

function _custom_get_ublox_communication_checkbox_form_element() {
  return array(
    '#type' => 'checkbox','#title' => t('I consent to retaining my personal data for the purposes of receiving personalized marketing materials,offers,invitations to webinars and other similar events. To learn more,read our <a'),'#required' => FALSE,);
}

测试前清除所有缓存