【问题标题】:Identify form control id in Drupal 7 Forms API在 Drupal 7 Forms API 中识别表单控件 ID
【发布时间】:2015-02-04 06:05:45
【问题描述】:

Forms API 中的表单控件有 id 吗?以下是我的示例代码:

function myid_user_page_form(){  
    $form = array();
    $form['id'] = array(
        '#type' => 'fieldset',
        '#title' => t('ID Information'),
        '#collapsible' => TRUE, 
        '#collapsed' => FALSE,
    );  
    $form['id']['myphoto_button'] = array(
        '#type' => 'button', 
        '#value' => '...',
        '#attributes' => array(
        'onclick' => "myphoto_options();",),  
    );
    return $form;
 }

对于这个非常简单的初学者问题很抱歉,但是如何在上面的示例中识别我的按钮 ID(例如)$form['id']['myphoto_button']?

【问题讨论】:

标签: drupal drupal-7 form-api


【解决方案1】:

#attributes 属性用于设置元素的 html 属性。 (like、id、class、style、onclick等)

我可以看到您正在使用它来绑定onclick 处理程序。所以,它为了给你的按钮一个 id:

$form['id']['myphoto_button'] = array(
    '#type' => 'button', 
    '#value' => '...',
    '#attributes' => array(
        'onclick' => "myphoto_options();",
        'id'      => 'YOUR-BUTTON-ID',
    ),  
);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多