Not able to assign value to hidden form field using form_alter hook 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(&amp;$form, &amp;$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-&gt;uid;
    }
}


But not able to set the value for that field.

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

&lt;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"&gt;








Thanks in advance.
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(&amp;$form, &amp;$form_state) {    
$form['field_my_field']['#parents'] = array('field_my_field');
form_set_value($form['field_my_field'],array('und' =&gt; array(0 =&gt; array('value' =&gt; $new_value))),$form_state);


}

For reference please go through link