I am trying to set a default value using hook_form_alter on an entity form, and the usual thing I do is not working, can anyone see why?

Here is the dsm($form) ...

enter image description here

My module is called "pinboard" and the form ID is "pinboard_entityform_edit_form" which is in the array and I used dsm($form_id);

function pinboard_form_alter(&$form, &$form_state, $form_id){
  if($form_id == "pinboard_entityform_edit_form"){

        $form['actions']['submit']['#value'] = t('Send Enquiry');
        $form['field_your_name']['und']['#default_value'] = t('Joe Bloggs');

This is just a simple example, I am well aware I can set a default value through the UI, I will be replacing "Joe Bloggs" with my own variable once I get this working.

The first line works perfectly and changes the submit button text, but the second line does not set a default value on the your name field.

What am I missing?

  • 1
    Have a glance through this, should help to clear it up
    – Clive
    Nov 27 '15 at 14:23
  • Yep, you nailed it, thanks Clive. I was missing the ['0']['value'], stupid rookie mistake!!
    – Collins
    Nov 27 '15 at 14:26

Browse other questions tagged or ask your own question.