2

I made a custom content type with a couple of fields. If i go to node/add/custom-content-type I have a dsm of $form in my .module file which shows the array in a krumo just fine. In the krumo the array shows the custom fields made in field UI, and each field has an array of 6 elements. Here's where the key #value and #default_value are missing.

Instead, the 6 keys are:

#type (String, 9 characters ) container
#attributes (Array, 1 element)
#weight (String, 1 characters ) 1
#tree (Boolean) TRUE
#language (String, 3 characters ) und
und (Array, 13 elements)

So obviously the question is how do I get those keys/attributes of that field in that array?

1

See Why is hook_form_alter() so messy? for a bit of background, but basically you need to drill further down into the array.

Assuming it's a standard text field you would set, for example, the default value like so:

$form['field_name'][LANGUAGE_NONE][0]['value']['#default_value'] = 'foo';
  • 1
    right, agree with you. – Yusef Sep 5 '12 at 12:16
  • Yes! I found it: great :) – Immers Sep 5 '12 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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