Importance Of #attached Attribute In Drupal Forms API Reference, A New Feature In Drupal 7

====================================================================

function myModule_personal_detail_form($form, &$form_state) {
    $form = array();
    $form['cust_first_name'] = array(
        '#type' => 'textfield',
    );
    
    $form['cust_last_name'] = array(
        '#type' => 'textfield',
    );
    
    $form['cust_age'] = array(
        '#type' => 'textfield',
        '#maxlength' => 3,
    );

    // Get the path to the module
    $path = drupal_get_path('module', 'myModule');

    // Attach the CSS and JS to the form
    $form['#attached'] = array(
        'css' => array(
            'type' => 'file',
            'data' => $path . '/css/personal_detail.css',   // location where you have put your css file.
        ),
        'js' => array    (
            'type' => 'file',
            'data' => $path . '/js/personal_detail.js',      // location where you have put your js file.
        ),
    );
    
    return $form;
}

=================================================================== Apart form using drupal_add_js() and drupal_add_css() methods for adding js and css files respectively, there is benifit of using #attached attribute over the above two methods on a form level, that the form can be altered by another module usinghook_form_alter(), just by changing the stylesheets and scripts if necessary in the hook and rebuilding the form.

150 150 Burnignorance | Where Minds Meet And Sparks Fly!