在Drupal 7 Forms API中识别表单控件ID

时间:2015-02-04 06:05:46

标签: drupal drupal-7 form-api

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']?

1 个答案:

答案 0 :(得分:0)

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

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

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