How to remove default fields from Drupal form

meenakshi - April 28, 2009 - 11:26

How can i remove below fileds from Drupal's form,

1) Theme configuration
2) Revision Information
3) Comment Settings
4) Authoring information
5) Publishing option
6) Book outline
7) File attachment
8) URL path settings
9) Input Format

Thanks.

place this in your theme/template.php file

rkdeveloper - April 28, 2009 - 11:33

function modulename_form_alter(&$form,$form_state,$form_id){
          switch ($form_id) {
             case 'formidhere':
                    
                unset($form['author']);//remove authoring
                unset($form['menu']);//remove menu options
                unset($form['options']);//remove publishing options
                unset($form['comment_settings']);//remove comment settings
                unset($form['path']);//remove url path settings (if path module is enabled)
                unset($form['log']);//log box
                unset($form['body_filter']['filter']);//remove input format
unset($form['revision_information']);//revistion information 
}
}

replace modulename with some module name which you installed. and formidhere with form id in which you want to remove the things

RK

Re:place this in your theme/template.php file

meenakshi - April 28, 2009 - 12:21

rkdeveloper thanks for quick reply.
I have tried putting the above code in template.php file. But the feilds are still appear in the form.

have you replaced modulename and formid?

rkdeveloper - April 28, 2009 - 12:37

have you replaced modulename and formid? those are compulsory

RK

Re: have you replaced modulename and formid?

meenakshi - April 28, 2009 - 12:43

I am newbie to drupal.Kindly elaborate abt replacing modulename and formid. How can i get formid ?

echo $form_id;

rkdeveloper - April 28, 2009 - 13:20

this retruns form id. you can use this.

RK

Error After changing Module name

meenakshi - April 29, 2009 - 05:16

Drupal showing the below error when i changed modulename to "og"

Fatal error: Cannot redeclare og_form_alter() (previously declared in D:\WAMP Server\www\Drupal\sites\all\modules\og\og.module:1721) in D:\WAMP Server\www\Drupal\sites\all\themes\SmartDoc\template.php on line 85

Best way to discover other field names ?

Daves - October 30, 2009 - 11:33

Hi

What is the simplest way for me to discover the $form array key names for other fields in my node edit form ( the node contains CCK fields ) ?

Thanks

Dave

Problem Solved!

meenakshi - April 29, 2009 - 09:00

Hi rkdeveloper,

Now there are no unwanted fields on form.I'm just glad that I got it working. Thanks!

_

WorldFallz - October 30, 2009 - 14:04

uh-- how about just setting the appropriate permissions -- only the items for which a user has permissions will show up in the node edit form. If you still need to manually unset some things, you can use http://api.drupal.org/api/function/hook_form_alter.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

 
 

Drupal is a registered trademark of Dries Buytaert.