Posted by meenakshi on April 28, 2009 at 11:26am
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
place this in your theme/template.php file
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
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?
have you replaced modulename and formid? those are compulsory
RK
Re: have you replaced modulename and formid?
I am newbie to drupal.Kindly elaborate abt replacing modulename and formid. How can i get formid ?
echo $form_id;
this retruns form id. you can use this.
RK
Error After changing Module name
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 ?
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
Install devel.module and use
Install devel.module and use dpm($form) in your alter hook.
Unsetting fields can make the
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
...
}
}
Problem Solved!
Hi rkdeveloper,
Now there are no unwanted fields on form.I'm just glad that I got it working. Thanks!
_
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.