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.

Comments

rkdeveloper’s picture

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

meenakshi-2’s picture

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.

rkdeveloper’s picture

have you replaced modulename and formid? those are compulsory

meenakshi-2’s picture

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

rkdeveloper’s picture

this retruns form id. you can use this.

meenakshi-2’s picture

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

El Bandito’s picture

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

cafuego’s picture

Install devel.module and use dpm($form) in your alter hook.

cafuego’s picture

Unsetting fields can make the submit handler unhappy. If you really need to remove them and can't do it via permissions, you should use the #access property on each element instead.

function modulename_form_alter(&$form,$form_state,$form_id) {		
    switch ($form_id) {
        case 'formidhere':
            $form['author']['#access'] = FALSE;//remove authoring 
            $form['menu']['#access'] = FALSE;//remove menu options
            ...
    }
}
meenakshi-2’s picture

Hi rkdeveloper,

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

WorldFallz’s picture

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.