11

How can I hide a field when creating a node, but displaying it when editing a mode?

16

If I understand your question, I think that you can use a custom module (in this example, the name of the module is test_remove_field) and include the following code:

function test_remove_field_form_alter(&$form, &$form_state) {

    if (arg(0) == 'node' && arg(1) == 'add') {
    $form['field_test']['#access'] = 0;
    }

}

Note: remember that field_test must be your respective field name.

  • thank you. i m not familiar with creating module. is there any css or theme tips to do this? – user780 Sep 15 '11 at 6:41
  • Hello a.v., regarding your question, yes, is possible, you can add the same IF declaration in page.tpl.php (inside head zone) and add inside the declaration the respective (ID or CLASS) CSS rule to remove your field: #field_name_test { display:none;} – cigotete Sep 15 '11 at 15:08
  • 1
    here is the code of my test: <?php if (arg(0) == 'node' && arg(1) == 'add') { ?> <style type="text/css"> #field_name_test { display:none; } </style> <?php } ?> – cigotete Sep 15 '11 at 15:10
4

The Field Permissions module allows you to set field level permissions:

  • Create field (edit on content creation)
  • Edit field regardless of content author
  • Edit own field on content created by the user
  • View field regardless of content author
  • View own field on content created by the user

You can use these options to enable role based permission for a field.

When permissions are enabled, access to this field is denied by default and explicit permissions should be granted to the proper user roles from the permissions administration page. On the other hand, when these options are disabled, field permissions are inherited from the content view and/or edit permissions. In example, users allowed to view a particular node will also be able to view this field, and so on.

Field permissions

3

I'd use hook_form_alter() and set the ['#access'] property to FALSE just like the answer by @moon.watcher.

If you're in Drupal 6, you'd need a module for doing this. In Drupal 7 you can call hook_form_alter() from your template.

2

This is a use case for the Rules Form Support Module - https://www.drupal.org/project/rules_forms.

Features include:

  • Activate events for form creation, validation, and submission on a form-by-form basis.
  • Target individual form elements or the entire form in conditions and actions. Manipulate the attributes of a form element like title, description, weight, and more.
  • Validate the values of form elements during form validation.
  • Set form errors when rule-based validation fails.
  • Redirect users to a different page upon viewing or submitting a form.
  • Examine the attributes of elements in active forms with the element inspection tool.
0

You could take over the node add/edit form with Panel pages. With this, you can pick and choose what you want on the form.

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.