How to fix error Undefined index: parent in taxonomy_form_term_submit()? I got below error on my site recently.


  Notice: Undefined index: parent in taxonomy_form_term_submit() (line 829 of /var/www/Sites/xxxxx/modules/taxonomy/taxonomy.admin.inc).


I google it and find there is an old issue but seems nothing solved.

In the issue, @Cracu did mention some part of core code may cause this error:

  if (!variable_get('taxonomy_override_selector', FALSE)) {
    $parent = array_keys(taxonomy_get_parents($term-&gt;tid));
    $children = taxonomy_get_tree($vocabulary-&gt;vid, $term-&gt;tid);

    // A term can't be the child of itself, nor of its children.
    foreach ($children as $child) {
      $exclude[] = $child-&gt;tid;
    }
    $exclude[] = $term-&gt;tid;

    $tree = taxonomy_get_tree($vocabulary-&gt;vid);
    $options = array('&lt;' . t('root') . '&gt;');
    if (empty($parent)) {
      $parent = array(0);
    }
    foreach ($tree as $item) {
      if (!in_array($item-&gt;tid, $exclude)) {
        $options[$item-&gt;tid] = str_repeat('-', $item-&gt;depth) . $item-&gt;name;
      }
    }
    $form['relations']['parent'] = array(
      '#type' =&gt; 'select',
      '#title' =&gt; t('Parent terms'),
      '#options' =&gt; $options,
      '#default_value' =&gt; $parent,
      '#multiple' =&gt; TRUE,
    );

  }


I try to look into the latest core, this part of code is still there with same logics. Unfortunately, I need taxonomy_override_selector be TRUE.

Apart from setting taxonomy_override_selector to FALSE or adding new form validation handler to set $form_state['values']['parent'].

Do anyone know if there is solution for that?
There's a couple of ways you could go about the problem:


Patch Core: If there's no outstanding issue for the problem, alter core, create a patch &amp; bug report, and submit your patch. You can manage your patch in your deployment process until the patch is accepted upstream.
Custom Module: Looking at the comment above the code you posted, it was authored with the intention that someone might need to alter the form ("Contrib modules can then intercept before hook_form_alter to provide scalable alternatives."). You can use a HOOK_form_taxonomy_form_term_alter invocation to alter the submission handler or the form array to mitigate the warning introduced.