4

I have 7 fields in a content type and the last field value, I am updating programmatically. So it should not be displayed when adding content to it. What should I do.

3
  • You can use computed field module to add last field. Nov 22 '13 at 6:00
  • will it hides a field??? @Jayendra Kainthola
    – Chella
    Nov 22 '13 at 6:02
  • Yes, It will hide the field and even you can add token value for calculation in computed field. Nov 22 '13 at 6:06
2

The way I prefer is to use Computed Field module. Not only it creates a field that's not editable for users, it also takes care about hooks, cache, and lets you simply choose recalculation strategy (on save / on display). All you really need to care with it, is the very code that calculates field's value.

1

Hope this will help field_hidden

Field Hidden defines five hidden field types

text, long text integer, decimal, floating-point Hidden in forms Hidden fields are always rendered as elements in forms. enter image description here

0
0

Go and edit the node content type and in Field Settings change the Field Visibility and Permission. enter image description here

Just remove the edit permission to any role.

0

You can add a field in your form programmatically as follows :

function hook_form_alter($form,&$form_state, $form_id) {

 if ($form_id == 'your_form_id') {

$field_hidden_value = 'enter your computed value here' ;
   $form['field_hidden'] = array(
      '#type' => 'value',
      '#value' => $field_hidden_value,
   );

  }
}
0

If you are looking to avoid creating a custom module/using code:

Then:

  • Setup a new rule with the event: Begin [your form name] being built
  • Setup a new action: Rules Forms > Set an attribute of an element in the form
  • Set the attribute #access to false

The form element will now be hidden.

If you are trying to avoid creating a custom module, this does the trick.

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.