1

I have a content type with fields added from the core module and I want to hide some fields in the edit form, but not in the page node.

I've tried with

$form['my_field']['#access'] = FALSE; in my custom module, but that hides the field in the node page too. Is there any other way to hide the field only in edit form?

My approach was to wrap some fields into a two columns. Here's what I've tried:

  <?php 
    /*
     * Implements hook_form_alter().
     */

    function my_module_form_alter (&$form, &$form_state, $form_id) {
         switch ($form_id) {

          case 'custom_node_form':

          $form['column_left'] = array(
          '#prefix' => '<div class="column-left">',
          '#suffix' => '</div>',
            );

           $form['column_left']['custom_field'] = $form['custom_field'];
           $form['custom_field']['#access'] = FALSE;
         break; 
       }
    }

Unfortunately it's disabling into the page node too. I'm using Display suite for the full content and I'm pretty much sure that the field is not hidden from there.

  • case 'content_type_form': is mising ? – pico34 Sep 11 '13 at 15:01
  • hook_form_alter cannot hide it on the node page – pico34 Sep 11 '13 at 15:03
  • I forgot to copy that line, but in my module is already created. I have some difficulties in stackexhange with copying the codes and with the color codes. :) – user2519032 Sep 11 '13 at 15:04
  • @pico34 Somehow it's hiding in the node page too. Let's say when I'm adding a new content, filling the title field and when I save the content, the title is missing in the node page. If I remove $form['column_left']['title_field'] = $form['title_field']; $form['title_field']['#access'] = FALSE; it's ok, but the whole approach is to wrap the fields in columns. – user2519032 Sep 11 '13 at 15:12
  • I guess this module can help you. – arpitr Sep 11 '13 at 15:23
1

Have you checked

admin/structure/types/manage/my_content_type/display

Your field is probably hidden here.

Otherwise, hook_form_alter is only for form you are right

An other attribute is :

$form['my_field']['#disabled'] = TRUE;
  • I'm using Display suite and the field is not hidden from there. I have a textfield and $form['my_field']['#disabled'] = TRUE; is only disabling the input form. Anyway I've added more info in my thread. – user2519032 Sep 11 '13 at 14:56
0

If you simply want it not to show on your edit form, modify your theme css file

.element_class {
  display: none;
}
  • 1
    bad idea if field is confidential, disable css reveals it – pico34 Sep 11 '13 at 14:37
  • 1
    Yes, that's right. Using CSS is not the right solution in this case. – user2519032 Sep 11 '13 at 15:01

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.