I am using Drupal 7. I have a Content Type called Request. I have two fields "Manager Name" (type Text) and "Manager Email Address" (type Email). When the user creates a new node of type Request, I want to pre-fill these fields with "Hello World" and "nobody@yahoo.com". Here is what I have tried so far (This is all in mymodule_form_node_form_alter):

$form['field_manager_name']['und']['#default_value'] = "Hello World";
$form['field_manager_name']['und']['#suffix'] = "Enter in the name of your immediate supervisor.";
$form['field_manager_email_address']['und']['#default_value'] = "nobody@yahoo.com";
$form['field_manager_email_address']['und']['#suffix'] = "Enter in the email address of your immediate supervisor.";

The two suffixes are working. When I create a new node of type Request, the suffix text appears under the field name, as expected. But the "default_value" fields are not working. What am I doing wrong?


instead of $form['field_FIELD_NAME']['und']['#default_value'] you should use $form['field_FIELD_NAME'][LANGUAGE_NONE][0]['value']['#default_value']
try something like:

$form['field_manager_name'][LANGUAGE_NONE][0]['value']['#default_value'] = 'hello world';
$form['field_manager_email_address'][LANGUAGE_NONE][0]['email']['#default_value'] = "nobody@yahoo.com";
  • 1
    If the second one is a field from the email field module, I'm pretty sure the column name is email rather than value
    – Clive
    May 29 '20 at 18:27
  • Why is LANGUAGE_NONE preferred over "und"? I admiit, I don't even know what either of those mean.
    – MrSnrub
    May 29 '20 at 18:35
  • 1
    @Clive: Yes, "email" worked. Thanks.
    – MrSnrub
    May 29 '20 at 18:36
  • Yes @Clive you are right; i will update my answer!
    – berramou
    May 29 '20 at 19:19

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.