1

Is it possible, not only to give a CCK field a default value, but also make it non-editable by the user?

4
  • 1
    What versions (drupal/cck) are you using? – Andrew Sledge Nov 10 '11 at 15:59
  • Do content editor need to be able to see the value on the edit page, or does it just need to be rendered upon pageview? – mpdonadio Nov 10 '11 at 16:37
  • @Andrew using Drupal 6.22 – Jane Nov 10 '11 at 16:53
  • @MPD it doesn't really matter either way... – Jane Nov 10 '11 at 16:54
2

I used jquery to do just that.

(function($) {

$(document).ready(function() {

// make the number field uneditable!
$('#edit-field-entry-custom-id-und-0-value').attr("disabled", "true");
}); 

}(jQuery));

to be safer however, in case someone disables javascript you could add this to your themes template.php

function YOURTHEME_form_alter(&$form, $form_state, $form_id) {
 if($form_id == 'YOUR_FORM_ID') {
  $form['FIELD_NAME']['#disabled'] = TRUE;

  // YOU CAN UNCOMMENT THE BELOW FOR EXTRA HELPFUL DETAILS
  // GET FORM ID UNCOMMENT BELOW
  // drupal_set_message("Form ID is : " . $form_id);
  // GET ALL FORM ELEMENTS UNCOMMENT BELOW
  // drupal_set_message(dprint_r($form, TRUE));
 }
}
1
  • 2
    You would have to move the form_alter to a module if you have a different admin theme configured, and if content editing uses the admin theme. Double check settings on /admin/settings/admin – mpdonadio Nov 10 '11 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.