0

I am actualy trying to build up a dragable table, but for some reason after implementing the theme_function, my submit handler is not longer getting called.

This is what my Code actualy looks like:

function he_ministerienschalter_theme($existing, $type, $theme, $path) {
  $themes = array(
    'he_ministerienschalter_admin_form' => array(
      'render element' => 'element',
    ),
  );
  return $themes;
}


/**
  * Implements the ministerschalter admin form
  */

function he_ministerienschalter_admin_form($form, &$form_state, $form_id, $item) {

  $domainnames = he_ministerienschalter_domainselect();

  $count = 0;
  $form['ressortswitch'] = array(
    '#prefix' => '<div id="curve-attributes">',
    '#suffix' => '</div>',
    '#tree' => TRUE,
    '#theme' => 'he_ministerienschalter_admin_form',
  );
  foreach ($domainnames as $key => $domainname) {
      $form['ressortswitch'][$key]['domainID-'.$key] = array(
        '#type' => 'value',
        '#value' => $domainname['domain_id'],        
      );
      $form['ressortswitch'][$key]['domainname-'.$key] = array(
        '#type' => 'item', 
        '#title' => $domainname['sitename'], 
        '#size' => 60, 
        '#maxlength' => 128, 
      );
      $form['ressortswitch'][$key]['domainshort-'.$key] = array(
        '#type' => 'textfield',
        '#default_value' => $domainname['sitename'],
      );
      $form['ressortswitch'][$key]['weight-'.$key] = array(
        '#type' => 'textfield',
        '#default_value' => !empty($domainname['domain_weight']) ? $domainname['domain_weight'] : '0',
        '#size' => 3,
        '#attributes' => array('class' => array('item-row-weight')),
      );
      $count++;
    }

    $form['ressortswitch']['count'] = array(
      '#type' => 'hidden',
      '#value' => $count,
    );
    $form['ressortswitch']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save Settings'),
    );

  return $form;
}

/**
  * Theme callback for the he_ministerienschalter_admin_form
  */

function theme_he_ministerienschalter_admin_form($variables) {
  $element = $variables['form'];
  drupal_add_tabledrag('ressortswitch_table', 'order', 'sibling', 'item-row-weight');
  $header = array(
    t('Domainname'),
    t('Domainshort'),
    t('Weight')  
  );

  $element_items = array();

  foreach($element['ressortswitch'] as $id => $record) {
    if(is_int($id)) {
      $element_items[] = $record;
    }
  }

  $rows = array();
  foreach ($element_items as $id => $item) {
      $domainNAME[$id] = $item['domainname-'.$id];
      $domainSHORT[$id] = $item['domainshort-'.$id];
      $domainWEIGHT[$id] = $item['weight-'.$id];

    $rows[] = array(
      'data' => array(
        drupal_render($domainNAME[$id]),
        drupal_render($domainSHORT[$id]),
        drupal_render($domainWEIGHT[$id]),
      ),
      'class' => array('draggable'),
    );
  }

  $output = theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array('id' => 'ressortswitch_table'),
  ));

  $output .= drupal_render($element['ressortswitch']['submit']);

  return $output;
}



/**
  * Implements hook_form_submit
  */

function he_ministerienschalter_admin_form_submit($form, &$form_state, $item) {
  db_delete('he_ministerienschalter')
  ->execute();
  $count_domains = $form_state['values']['ressortswitch']['count'];
  $count = 0;
  // dpm($form_state);
  dpm($form_state);
  while($count < $count_domains) {
    db_insert('he_ministerienschalter')
      ->fields(array(
        'domain_id' => $form_state['values']['ressortswitch'][$count]['domainID-'.$count],
        'domain_short' => $form_state['values']['ressortswitch'][$count]['domainshort-'.$count],
        'domain_weight' => $form_state['values']['ressortswitch'][$count]['weight-'.$count]
    ))
    ->execute();
    $count++;
  }
  drupal_set_message('Eingabe gespeichert');
}

Any idea how to solve that?

  • 'render element' => 'element', looks a bit suspect as you're looking for $element = $variables['form']; in the theme function. 'render element' => 'form', would make more sense – Clive Mar 20 '14 at 10:59
  • Changed it, but without luck :-/ – Sebastian Mar 20 '14 at 11:43
1

I Updated my theme function like this and now it works like a charm :-)

$output .= drupal_render($element['form_id']);
$output .= drupal_render($element['form_build_id']);
$output .= drupal_render($element['form_token']);

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.