I have a form in which field my_consultant_id is "Hidden integer" type field and having widget type as "Hidden field".

I am assigning the value to this field by using hook_form_alter

function threebl_summary_report_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == 'eck__entity__form_add_summary_report_comparative_client_gro‌​up') {
        global $user; 
        $form['field_created_by']['und'][0]['#default_value'] = (int) $user->uid;

But not able to set the value for that field.

If I inspect the form it shows html code for field like:

<div class="field-type-field-hidden-integer field-name-field-my-consultant-id field-widget-field-hidden form-wrapper" id="edit-field-my-consultant-id">

Thanks in advance.

  • Do you get any errors or it does not store the value to the database? The form submit handler is custom (share the code) or default?
    – mchar
    Feb 7, 2017 at 10:28
  • No errors...It does not store the value in database. I checked the value of $user->uid its correct Feb 7, 2017 at 10:34
  • Check this out: drupal.org/node/728398#comment-11519357
    – mchar
    Feb 7, 2017 at 10:52

2 Answers 2


I managed to do it by validate handler of the form. Using validate handler I assigned my value to the form variable before submit.

In form alter hook call validate handler like below

$form['#validate'][] = 'my_module_name_form_validate';

And following is the validate handler function code

function my_module_name_form_validate(&$form, &$form_state) {    
$form['field_my_field']['#parents'] = array('field_my_field');
form_set_value($form['field_my_field'],array('und' => array(0 => array('value' => $new_value))),$form_state);


For reference please go through link


I think you are missing default value.


$form["my_consultant_id"][LANGUAGE_NONE][0]['value']['#default_value'] = (int)$user->uid;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.