【问题标题】:Disable option of required in webform in Drupal 7在 Drupal 7 中禁用 webform 中的 required 选项
【发布时间】:2021-03-01 08:11:25
【问题描述】:

我的功能:

     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,但在删除所需选项后,它甚至不会从字段中删除所需的 (*) 检查。

【问题讨论】:

    标签: checkbox webforms drupal-7 required-field


    【解决方案1】:

    如果你只想使用一个复选框元素,你应该使用'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,
      );
    }
    

    测试前清除所有缓存

    【讨论】:

      猜你喜欢
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多