How to identify and target a form element? A similar question has been asked before: How do you identify a form element? 

I am using the Devel module and dpm($form) outputs the object nicely:



But I can't set/change the default value of a custom field. How do I target set the default value to 164 in this case?

$form['question_node_form']['field_points']['und']['0']['value']['#default_value'] = 164;


The above does not work and the points_field is blank.

EDIT (complete function):

function custom2_form_question_node_form_alter(&amp;$form, &amp;$form_state, &amp;$form_id) {
    drupal_set_message("Form ID is : " . $form_id);
    dpm($form);
    $form['question_node_form']['field_points']['und']['0']['value']['#default_value'] = 164;
}
You're calling the explicit hook_form_FORM_ID_alter for a start so $form_id will never be anything except question_node_form.

However the problem is you are trying to target a child of the form array. The top level array is already question_node_form. Your code should look like this:

function custom2_form_question_node_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    $form['field_points']['und']['0']['value']['#default_value'] = 164;
}


Debugging removed for clarity. Noticed we removed ['question_node_form'].

Also note you can't pass $form_id by reference (not that it matters) as it can't be changed.

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_form_FORM_ID_alter/7