I have custom_form, with node_reference_field.. When I add Any node and leave some require field then I submit .. the node_reference_field fail and become [nid:und]

function custom_form_alter(&$form, &$form_state, $form_id) {
  $forms = array('register_node_form', 'session_node_form');
  if (in_array($form_id, $forms)) {
    if (empty($form['field_event_ref']['und'][0]['nid']['#default_value'])) {
      $form['field_event_ref']['und'][0]['nid']['#default_value'] = arg(3);
    $form['field_event_ref']['und'][0]['nid']['#disabled'] = True;

1 Answer 1

if ($form_id == 'register_node_form'){
    global $user;
       $nid = $form_state['build_info']['args'][0]->field_event_ref[LANGUAGE_NONE][0]['nid'];
    }  else {
    $nid = $form_state['build_info']['args'][0]->field_event_ref[LANGUAGE_NONE][0]['nid'] = arg(3);
     $form_state['build_info']['args'][0]->field_event_ref[LANGUAGE_NONE][0]['nid'] = $nid;

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.