0

I've created a content type with a link type field. When an user add this content type I want to prefill the link field with the user email. I've a create a new module named prefilllink with an alter hook :

function prefilllink_alter(&$form, &$form_state, $form_id) {
  dsm($form);
  switch($form_id) {
    case "job_node_form":
      $form["field_apply"]["und"][0]["value"]["#default_value"] = $user->mail;
      break;
  }
}

But it doesn't work... Any idea?

1
  • hook_form_alter().Instead of prefilllink_alter maybe try prefilllink_form_alter() Commented Sep 19, 2013 at 12:37

1 Answer 1

0

You need to implement either hook_form_alter() or hook_form_FORM_ID_alter() (there's no hook_alter() which is what your code is implementing at the moment).

The second is probably preferable as it targets the form you're interested in:

function prefilllink_form_job_node_form_alter(&$form, &$form_state, $form_id) {
  global $user;
  $form["field_apply"][LANGUAGE_NONE][0]["value"]["#default_value"] = $user->mail;
}
1
  • Thanks!! that wasn't the right hook name. i've added a email type field and now the correct syntax is : global $user; $form["field_email"][LANGUAGE_NONE][0]["email"]["#default_value"] = $user->mail;
    – Bibix
    Commented Sep 19, 2013 at 13:17

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