Skip to content

Instantly share code, notes, and snippets.

@jonhattan
Last active December 6, 2017 07:28
Show Gist options
  • Save jonhattan/5412454 to your computer and use it in GitHub Desktop.
Save jonhattan/5412454 to your computer and use it in GitHub Desktop.
Hide a field in node edit form and provide its value programatically.
<?php
/**
* Implements hook_form_FORM_ID_alter() for node type 'test'.
*
* Hide field_texto.
*/
function fieldautovalue_form_test_node_form_alter(&$form) {
$form['field_texto']['#access'] = FALSE;
}
/**
* Implements hook_node_Validate().
*
* Set value for field_texto for node type 'test'.
*/
function fieldautovalue_node_validate($node, $form, &$form_state) {
if ($node->type == 'test') {
$value = array(LANGUAGE_NONE => array(array('value' => 'lorem ipsum')));
form_set_value($form['field_texto'], $value, $form_state);
}
}
@lgrtm
Copy link

lgrtm commented Apr 20, 2013

Thk Jonhattan.
A good trick.

Keep the default value if you only hide it?


Well, i tested and work fine !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment