Hi!
I have created a new content type called 'complaint'. It has several fields like first name, last name, date of filing etc.
Creating the content is all fine.
While editing the already saved content (node) I want to disable the fields that have already been input by the user.
I also want to show different form elements from the same content type 'complaint' to different user based on some data in the profile table.
To achieve disabling form elements I was trying to modify content_form_alter($form_id, &$form) in content.module under cck module. I was hoping that iterating over the $form for all the elements I would be able to use
$form['field...._value']['#disabled'] = TRUE;
for the elements for which ['#default_value'] is not empty.
but I don't get the correct nesting in the array. I don't get how CCK stores data in the nested array.
Is there a better and easy way to selectively disable form elements if the form element already has some value in the previous save.
For example if the first name was saved while creating the content then first name should appear as disabled while last name should appear as enabled during form editing. Also the change should not affect anything during new content creation.
I am really challenged here and any help would be greatly appreciated. I hope Drupal has something better.
Thanks,
San
Comments
I think you are going about
I think you are going about this the wrong way - it doesn't seem that there is any reason that you would need to modify content.module.
You can use hook_form_alter (http://api.drupal.org/api/function/hook_form_alter/5) to accomplish this. You'll still need to tinker a bit, but at least you will be tinkering in the right place. If you aren't familiar with implementing a hook, it will involve creating a small custom module for your site in which to place the code.