0

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 "[email protected]". 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'] = "[email protected]";
$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?

1 Answer 1

1

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'] = "[email protected]";
4
  • 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
    Commented May 29, 2020 at 18:27
  • Why is LANGUAGE_NONE preferred over "und"? I admiit, I don't even know what either of those mean.
    – MrSnrub
    Commented May 29, 2020 at 18:35
  • 1
    @Clive: Yes, "email" worked. Thanks.
    – MrSnrub
    Commented May 29, 2020 at 18:36
  • Yes @Clive you are right; i will update my answer!
    – berramou
    Commented May 29, 2020 at 19:19

Your Answer

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

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