1

I have a node form for a specific content type that has many fields. I want to move these fields into field sets, and wrap that in a class to make it work with my theme. I've done this with hook_form_alter(), and everything is fine, for the most part. I am able to save fields, and the form is displayed correctly.

However, whenever I submit the node edit form, the title flips back to 'Array' and gives me the following errors:

Warning: mb_strlen() expects parameter 1 to be string, array given in drupal_strlen() (line 478 of mysite/includes/unicode.inc).
Notice: Array to string conversion in devel_watchdog() (line 531 of mysite/sites/all/modules/devel/devel.module).
Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1565 of mysite/includes/bootstrap.inc).

Here is my implementation of hook_form_alter(). It's very simple; all it does is set up the fieldsets, copy the needed form elements into them, and then unset the original element:

/**
 * Implements hook_form_id_alter()
**/
function my_module_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'my_content_type_node_form':
      $form['fieldset1'] = array(
        '#type' => 'fieldset',
        '#title' => t('Fieldset 1'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
        '#prefix' => '<div class="grid_4">',
        '#suffix' => '</div>',
      );
      $form['fieldset2'] = array(
        '#type' => 'fieldset',
        '#title' => t('Fieldset 2'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
        '#prefix' => '<div class="grid_4">',
        '#suffix' => '</div>',
      );
      $form['fieldset3'] = array(
        '#type' => 'fieldset',
        '#title' => t('Fieldset 3'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
        '#prefix' => '<div class="grid_4">',
        '#suffix' => '</div>',
      );

      //move elements into fieldset1
      $form['fieldset1']['title'] = $form['title'];
      unset($form['title']);

      $form['fieldset1']['field_origin_location'] = $form['field_origin_location'];
      unset($form['field_origin_location']);

      $form['fieldset1']['field_task_override'] = $form['field_task_override'];
      unset($form['field_task_override']);

      //move elements into fieldset2
      $form['fieldset2']['field_equipment'] = $form['field_equipment'];
      unset($form['field_equipment']);

      //move elements into fieldset3
      $form['fieldset3']['field_additional_troubles'] = $form['field_additional_troubles'];
      unset($form['field_additional_troubles']);

      $form['fieldset3']['field_resolution'] = $form['field_resolution'];
      unset($form['field_resolution']);

      $form['fieldset3']['field_repair_parts'] = $form['field_repair_parts'];
      unset($form['field_repair_parts']);

      $form['seperator'] = array(
        '#type' => 'markup',
        '#markup' => '<div class="clearfix"></div>',
      );
    break;
  }
}

When I run a debugger and step through it at the time of the error, I see that $form_state['node']->title is set to 'Array', but otherwise I can't determine what is setting it to an array.

The error disappears when this form_alter function is commented out or the module is disabled, so I know that something within this function is triggering the error.

Does anyone have clues of where to start looking to solve this issue? Is there, perhaps, some other thing that I need to do in order to move the form elements? Maybe I am missing a step? Or, is this maybe coming from another module's code and if so, is there a method to find that module?

0

Solved.

When I posted my code on here, I realized that I had a typo in Fieldset 2, where I was using '$form['device']['title'] = ...' instead of '$form['device']['field_equipment'] = ...'

After fixing the typo, everything is working as normal.

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.