【问题标题】:How can I set ID attribute for drupal 7 form elements?如何为 drupal 7 表单元素设置 ID 属性?
【发布时间】:2014-05-14 10:54:52
【问题描述】:

我想设置我正在使用表单 API 在模块中创建的表单元素的 ID 属性。

【问题讨论】:

    标签: drupal drupal-7 drupal-fapi


    【解决方案1】:
    //Here is an example 
    
    $form['name'] = array(
     '#type' => 'item',
     '#title' => t('Title'),
     '#attributes' => array(
        'id' => 'your-id',
     ),
    );
    

    【讨论】:

      【解决方案2】:

      使用#id property

      $form['foo'] = array(
        '#type' => 'textfield',
        '#title' => t('Bar'),
        '#id' => 'baz',
      );
      

      为确保唯一性,您可能应该在 ID 字符串上使用 drupal_html_id()

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-08
        • 2013-05-31
        • 1970-01-01
        相关资源
        最近更新 更多