I have field_employee and i want to get his default value from nid in url


To display it Like:
field_employee == $node->title; //As a default value

function _get_emp_name(){
 global $base_url;
  $current_url = $base_url . request_uri();
  $url_sub = substr($current_url, 0, explode('&', $current_url));
  $to_array = explode('&', $current_url);
  $ar_name = explode("/", $to_array[1], 2);
  $node = node_load($ar_name[1]);
  $name = $node->title;
  return $name;


Then with form_alter I use:

$form['field_employee']['und'][0]['target_id']['#default_value'] = _get_emp_name();

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.