cck

Create Uneditable CCK Text Fields

Following is a little gem I found here - http://www.coderintherye.com/disabled-cck-fields-in-node-forms

I actually have a need for this in an upcoming project so it's right on time.

The goal: Create two uneditable text fields that would display in the node edit form with default values and in the node view and be saved in the node object.

//$Id:

/**
* Implementation of hook_form_alter().
* For the news story content type
* Make some fields not editable and have default values
*/

function formedits_form_alter(&$form, &$form_state, $form_id) {

Change the size of a CCK input field

There appears to be two ways to alter the width of a cck textfield if the widget does not offer that option within its configuration settings.

1. Change it via css

#edit-field-list-phone-1-value {
  width: 100px;
}

2. Change it via a custom module

This link tells you how.

Access the nid of the node that the current node references

After much trial and alot of error I finally figured out how to access the nid of the node that the current node references. The code first tests that you are on a node, and not editing it. Then the node is loaded up. the tricky part was the ['nid'] part. Usually this is something like ['view'] or ['value'].

if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
  $node = node_load(arg(1));
  $customer_nid = $node->field_customer_name[0]['nid'];
}

  $output .= '<p>NodeRef: ' . $customer_nid . '</p>';
  print $output;

Syndicate content

Contact Me

Feel free to contact me.

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.