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.
-
You can use computed field module to add last field.– Jayendra KaintholaNov 22, 2013 at 6:00
-
will it hides a field??? @Jayendra Kainthola– ChellaNov 22, 2013 at 6:02
-
Yes, It will hide the field and even you can add token value for calculation in computed field.– Jayendra KaintholaNov 22, 2013 at 6:06
5 Answers
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.
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.
Go and edit the node content type and in Field Settings change the Field Visibility and Permission.
Just remove the edit permission to any role.
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,
);
}
}
If you are looking to avoid creating a custom module/using code:
- Install Rules (https://www.drupal.org/project/rules)
- Install Rules Form Support (https://www.drupal.org/project/rules_forms)
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.