Last active
December 6, 2017 07:28
-
-
Save jonhattan/5412454 to your computer and use it in GitHub Desktop.
Hide a field in node edit form and provide its value programatically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thk Jonhattan.
A good trick.
Keep the default value if you only hide it?
Well, i tested and work fine !