I already spend whole day on figuring out the reason of following error:

( ! ) Fatal error: Cannot use string offset as an array in includes/form.inc on line 986 

In my case it happen when I post the form.
Is there any easy way to determine what's wrong?

I'm working on someone's code and for me it's a bug. Drupal should help me understand what is going on and how I can fix that.

Comments

kenorb’s picture

Backtrace:
...
10. drupal_get_form( $form_id = 'foo_form', class stdClass { public $nid = '42'; ... } )
...
13. form_builder( $form_id = 'foo_form', $form = array ('env_id' => '1',...))
14. form_builder( $form_id = 'foo_form', $form = '\000', $form_state = array (...)
15. _form_builder_handle_input_element( $form_id = 'foo_form', $form = '\000', $form_state = array (...))

$form =  '\0' (length=1)
$form_id = 'foo_form'

$form_state =
&
array
  'storage' => null
  'submitted' => boolean false
  'env_id' => 
    array
      '#type' => string 'hidden' (length=6)
      '#value' => string '1' (length=1)
      '#weight' => int -5
  'vids' => 
    array
      '#tree' => boolean true
      'vid-114' => 
        array
          '#type' => string 'select' (length=6)
          '#title' => string 'foo title' (length=46)
          '#options' => 
            array
              33692 => string 'foo1' (length=19)
              33691 => string 'foo2' (length=21)
              33690 => string 'foo3' (length=18)
              33689 => string 'foo4' (length=23)
              33693 => string 'foo5' (length=5)
          '#value' => null
          '#multiple' => boolean false
          '#size' => int 4
          '#weight' => string '1' (length=1)
      'vid-113' => 
        array
          '#type' => string 'select' (length=6)
          '#title' => string 'foo title' (length=47)
          '#options' => 
            array
              33657 => string 'foo1' (length=42)
              33660 => string 'foo2' (length=36)
              33655 => string 'foo3' (length=39)
              33658 => string 'foo4' (length=40)
              33656 => string 'foo5' (length=20)
              33659 => string 'foo6' (length=20)
          '#value' => null
          '#multiple' => boolean false
          '#size' => int 4
          '#weight' => string '2' (length=1)
      'vid-115' => 
        array
          '#type' => string 'select' (length=6)
          '#title' => string 'some title' (length=50)
          '#options' => 
            array
              33699 => string 'Birth-11 months' (length=15)
              33698 => string '8-20 months' (length=11)
              33697 => string '16-26 months' (length=12)
              33696 => string '22-36 months' (length=12)
              33695 => string '30-50 months' (length=12)
              33694 => string '40-60+ months' (length=13)
          '#value' => null
          '#multiple' => boolean false
          '#size' => int 4
          '#weight' => string '-9' (length=2)
  'submit' => 
    array
      '#prefix' => string '<div class ="submit">' (length=21)
      '#type' => string 'submit' (length=6)
      '#value' => string 'Go' (length=2)
      '#suffix' => string '</div>' (length=6)
      '#weight' => int 10
  'values' => 
    array
      empty

$complete_form =
array
  'storage' => null
  'submitted' => boolean false
  'post' => 
    array
      'env_id' => string '1' (length=1)
      'vids' => 
        array
          'vid-115' => string '33697' (length=5)
      'form_build_id' => string 'form-78907340c22c913194996b6c9ca931f4' (length=37)
      'form_token' => string '46195776d5c7629b8534882c628d38a5' (length=32)
      'form_id' => string 'foo_form' (length=14)
      'op' => string 'Go' (length=2)
  'env_id' => 
    array
      '#type' => string 'hidden' (length=6)
      '#value' => string '1' (length=1)
      '#weight' => int -5
  'vids' => 
    array
      '#tree' => boolean true
      'vid-114' => 
        array
          '#type' => string 'select' (length=6)
          '#title' => string 'foo title' (length=46)
          '#options' => 
            array
              33692 => string 'foo1' (length=19)
              33691 => string 'foo2' (length=21)
              33690 => string 'foo3' (length=18)
              33689 => string 'foo4' (length=23)
              33693 => string 'foo5' (length=5)
          '#value' => null
          '#multiple' => boolean false
          '#size' => int 4
          '#weight' => string '1' (length=1)
      'vid-113' => 
        array
          '#type' => string 'select' (length=6)
          '#title' => string 'foo title' (length=47)
          '#options' => 
            array
              33657 => string 'foo1' (length=42)
              33660 => string 'foo2' (length=36)
              33655 => string 'foo3' (length=39)
              33658 => string 'foo4' (length=40)
              33656 => string 'foo5' (length=20)
              33659 => string 'foo6' (length=20)
          '#value' => null
          '#multiple' => boolean false
          '#size' => int 4
          '#weight' => string '2' (length=1)
      'vid-115' => 
        array
          '#type' => string 'select' (length=6)
          '#title' => string 'foo' (length=50)
          '#options' => 
            array
              33699 => string 'Birth-11 months' (length=15)
              33698 => string '8-20 months' (length=11)
              33697 => string '16-26 months' (length=12)
              33696 => string '22-36 months' (length=12)
              33695 => string '30-50 months' (length=12)
              33694 => string '40-60+ months' (length=13)
          '#value' => null
          '#multiple' => boolean false
          '#size' => int 4
          '#weight' => string '-9' (length=2)
  'submit' => 
    array
      '#prefix' => string '<div class ="submit">' (length=21)
      '#type' => string 'submit' (length=6)
      '#value' => string 'Go' (length=2)
      '#suffix' => string '</div>' (length=6)
      '#weight' => int 10
  '#parameters' => 
    array
      0 => string 'foo_form' (length=14)
      1 => 
        array
          'storage' => null
          'submitted' => boolean false
          'post' => 
            array
              'env_id' => string '1' (length=1)
              'vids' => 
                array
                  'vid-115' => string '33697' (length=5)
              'form_build_id' => string 'form-78907340c22c913194996b6c9ca931f4' (length=37)
              'form_token' => string '46195776d5c7629b8534882c628d38a5' (length=32)
              'form_id' => string 'foo_form' (length=14)
              'op' => string 'Go' (length=2)
      2 => 
        object(stdClass)[4]
          public 'nid' => string '42' (length=2)
          public 'type' => string 'dynamic_content' (length=15)
          public 'language' => string '' (length=0)
          public 'uid' => string '1' (length=1)
          public 'status' => string '1' (length=1)
          public 'created' => string '1273743351' (length=10)
          public 'changed' => string '1273750737' (length=10)
          public 'comment' => string '0' (length=1)
          public 'promote' => string '1' (length=1)
          public 'moderate' => string '0' (length=1)
          public 'sticky' => string '0' (length=1)
          public 'tnid' => string '0' (length=1)
          public 'translate' => string '0' (length=1)
          public 'vid' => string '42' (length=2)
          public 'revision_uid' => string '1' (length=1)
          public 'title' => string 'Test' (length=4)
          public 'body' => string '' (length=0)
          public 'teaser' => string '' (length=0)
          public 'log' => string '' (length=0)
          public 'revision_timestamp' => string '1273750737' (length=10)
          public 'format' => string '2' (length=1)
          public 'name' => string 'admin' (length=5)
          public 'picture' => string '' (length=0)
          public 'data' => string 'a:0:{}' (length=6)
          public 'env_id' => string '1' (length=1)
          public 'parent' => string '0' (length=1)
          public 'weight' => string '0' (length=1)
          public 'has_children' => string '0' (length=1)
          public 'excerpt' => boolean false
          public 'teaser_format' => string '2' (length=1)
          public 'taxonomy' => 
            array
              empty
          public 'files' => 
            array
              empty
          public 'nodewords' => 
            array
              'abstract' => 
                array
                  'value' => string '' (length=0)
              'canonical' => 
                array
                  'value' => string '' (length=0)
              'copyright' => 
                array
                  'value' => string '' (length=0)
              'dc.contributor' => 
                array
                  'value' => string '' (length=0)
              'dc.creator' => 
                array
                  'value' => string '' (length=0)
              'dc.date' => 
                array
                  'value' => 
                    array
                      'month' => string '5' (length=1)
                      'day' => string '13' (length=2)
                      'year' => string '2010' (length=4)
              'dc.title' => 
                array
                  'value' => string '' (length=0)
              'description' => 
                array
                  'value' => string '' (length=0)
              'keywords' => 
                array
                  'value' => string '' (length=0)
              'location' => 
                array
                  'latitude' => string '' (length=0)
                  'longitude' => string '' (length=0)
              'pics-label' => 
                array
                  'value' => string '' (length=0)
              'revisit-after' => 
                array
                  'value' => string '1' (length=1)
              'robots' => 
                array
                  'value' => 
                    array
                      'noarchive' => int 0
                      'nofollow' => int 0
                      'noindex' => int 0
                      'noodp' => int 0
                      'nosnippet' => int 0
                      'noydir' => int 0
                  'use_default' => int 0
          public 'build_mode' => int 0
          public 'readmore' => boolean false
          public 'content' => 
            array
              'body' => 
                array
                  '#value' => string '' (length=0)
                  '#weight' => int 0
              '#body' => 
                array
                  '#value' => string '' (length=0)
                  '#weight' => int 1
  '#build_id' => string 'form-b2af98d1ffe0f73f8e231118ad49d837' (length=37)
  '#type' => string 'form' (length=4)
  '#programmed' => boolean false
  'form_build_id' => 
    array
      '#type' => string 'hidden' (length=6)
      '#value' => string 'form-b2af98d1ffe0f73f8e231118ad49d837' (length=37)
      '#id' => string 'form-b2af98d1ffe0f73f8e231118ad49d837' (length=37)
      '#name' => string 'form_build_id' (length=13)
  '#token' => string 'foo_form' (length=14)
  'form_token' => 
    array
      '#id' => string 'edit-foo-form-form-token' (length=30)
      '#type' => string 'token' (length=5)
      '#default_value' => string '46195776d5c7629b8534882c628d38a5' (length=32)
  'form_id' => 
    array
      '#type' => string 'hidden' (length=6)
      '#value' => string 'foo_form' (length=14)
      '#id' => string 'edit-foo-form' (length=19)
  '#id' => string 'foo-form' (length=14)
  '#description' => null
  '#attributes' => 
    array
      empty
  '#required' => boolean false
  '#tree' => boolean false
  '#parents' => 
    array
      empty
  '#method' => string 'post' (length=4)
  '#action' => string '/node/42' (length=8)
  '#submit' => 
    array
      0 => string 'foo_form_submit' (length=21)
      1 => string 'cookie_cache_bypass_submit' (length=26)
  '#after_build' => 
    array
      0 => string 'checkall_form_after_build' (length=25)
      1 => string 'wysiwyg_process_form' (length=20)
  '#post' => 
    array
      'env_id' => string '1' (length=1)
      'vids' => 
        array
          'vid-115' => string '33697' (length=5)
      'form_build_id' => string 'form-78907340c22c913194996b6c9ca931f4' (length=37)
      'form_token' => string '46195776d5c7629b8534882c628d38a5' (length=32)
      'form_id' => string 'foo_form' (length=14)
      'op' => string 'Go' (length=2)
  '#processed' => boolean false
Code:

function foo_view(&$node, $teaser = FALSE, $page = FALSE) {
...
    $output = drupal_get_form('foo_form', $node);
    $node->content['step1'] = array(
      '#value' => $output,
      '#weight' => 3,
    );
    return $node;
}

function foo_form(&$form_state, $node) {
  $form_state['env_id'] = array(
    '#type' => 'hidden',
    '#value' => $node->env_id,
    '#weight' => -5,
  );

  $form_state['vids'] = array('#tree' => TRUE);

  foreach ($config as $vocab) {
    $vname = taxonomy_vocabulary_load($vocab['vid'])->name;

    $multiselect = $vocab['multiselect'] ? TRUE : FALSE;
    $multiselect = FALSE;
    $form_state['vids']['vid-' . $vocab['vid']] = array(
      '#type' => 'select',
      '#title' => 'Select value for ' . $vname,
      '#options' => dw_get_config_terms($vocab),
      '#multiple' => $multiselect,
      '#size' => 4,
      '#weight' => $vocab['weight']
    );
  }
  $form_state['submit'] = array (
    '#prefix' => '<div class ="submit">',
    '#type' => 'submit',
    '#value' => 'Go',
    '#suffix' => '</div>',
    '#weight' => 10,
  );

  return $form_state;
}

function foo_form_submit($form, &$form_state) {
  $redirect_url = NULL;
  $form_post = $form_state['clicked_button']['#post'];

  foreach($form_post['vids'] as $vocab) {
...
  }

  $path = 'somewhere';
  drupal_goto(NULL, $path);
}
kenorb’s picture

Similar issues:
#783124: Error: Cannot Use String Offset.. Form.Inc
#743666: Back button is not working on review page
#351847: Cannot use string offset as an array..
#346020: Fatal error when importing
#358328: Error while accessing View Tool
#684580: Recieve error after attempting to change css 3 selector.
#619918: Support for mysqli
#535642: Fatal error: Cannot use string offset as an array in /home3/flirtwit/public_html/Gator/includes/form.inc on line 979
#280682: PHP Fatal Error when reply OG post commit
#238290: Drupal 6.x port
#224118: Views as block and then configure
#466696: User create fails while generating a username with a whitespace
#353947: Fatal error: Cannot use string offset as an array in /home/pelicanb/public_html/includes/form.inc on line 978
#620420: "Fatal error" when trying to edit an Invoice
#707626: Fatal Error Cannot use string offset as an array
#126920: Fatal error: Cannot use string offset as an array form.inc on line 676
#737336: Blank page after "move to junk"
#342991: Port HS support for Taxonomy Views to Drupal 6
#610398: updating a node doesn't delete the cache file
#507892: Fatal error when submitting another form on the same page as aes_view_password_form
#535642: Fatal error: Cannot use string offset as an array in /home3/flirtwit/public_html/Gator/includes/form.inc on line 979
http://drupal.org/node/754194
http://drupal.org/node/741272
http://drupal.org/node/436312
http://drupal.org/node/652974
http://drupal.org/node/354601
http://drupal.org/node/255406#comment-834226
http://drupal.org/node/367234
http://drupal.org/node/368073
http://drupal.org/node/465062
http://drupal.org/node/245014
http://drupal.org/node/381820
http://drupal.org/node/381820
http://drupal.org/node/395438

Those issue are related to the same Drupal error.
Is there any common solution or some method of tracking these issues to prevent creating new issues related to that problem?
Any explanation why this happen so often?

ljrweb’s picture

any progress on this???

this is happening to me using hook_form_alter() in one of my custom modules..

thanks

heine’s picture

Title: ( ! ) Fatal error: Cannot use string offset as an array in includes/form.inc on line 986 » Fatal error: Cannot use string offset as an array in includes/form.inc on line 986

@kenorb, the error indicates an incorrectly build form. In your case; You return $form_state from the formbuilder instead of a properly build form array. You also modify $form_state in the formbuilder.

@ljrweb, see the FAPI documentation, or post a support request in the forum.

damien tournoud’s picture

Category: bug » support
ljrweb’s picture

checking the apache logs:

child pid 1030 exit signal Segmentation fault (11)

that seems to be whats causing the issue for me.. apache crashing on the script i believe..

not sure how to fix it.

Anonymous’s picture

Status: Active » Postponed (maintainer needs more info)

Is support still needed for this issue? If not, I recommend closing.

kenorb’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Workaround is to use xdebug or other debuggers or print&die methods.