Posts

Showing posts from March, 2012

Code snippet: How to set the disabled or readonly attribute of a CCK field

Here's a code snippet that you can use to set the disabled attribute of a CCK field. First, you need to create a small module containing the following code: ssf /** * @file * Custom module to set the disabled attribute of CCK fields. */ /** * Implementation of hook_form_alter(). */ function mysnippet_form_alter(&$form, $form_state, $form_id) { if (isset($form['type']) && isset($form['#node'])) { // Use this check to match node edit form for a particular content type. if ('mytype_node_form' == $form_id) { $form['#after_build'][] = '_mysnippet_after_build'; } // Use this check to match node edit form for any content type. // if ($form['type']['#value'] .'_node_form' == $form_id) { // $form['#after_build'][] = '_mysnippet_after_build'; // } } } /** * Custom after_build callback handler. */ function _mysnippet_after_build($form, &$form_state) { // Use