Как показать только поля со значениями и скрыть поля без значений? - PullRequest
0 голосов
/ 17 марта 2011

Я пытаюсь, чтобы этот код отображал только те поля, которые имеют значения, любые поля, которые не имеют значений, не должны отображаться. Кажется, он не работает

Есть идеи, что я делаю не так?

Моя простая тестовая форма здесь http://www.healthybrighton.co.uk/wse/node/1844

/**
 * Build a table of submitted values
 *
 * @param $form_vals array Submitted form data
 * @param $select_mapping array Map select components to their value|label chocies
 * @return HTML of the themed table
 */       
function _format_form_state($form_vals = array(), $select_mapping) {
  $output = '';  
  $header = array();
  $rows = array();    

  if (!empty($form_vals)) {

    foreach ($form_vals as $component_name => $component_value) {
      $rows = array_merge(
        $rows,
        _add_component_row(
          $component_name,
          $component_value,
          0,
          $select_mapping
        )
      );
    }
  }



  $output .= theme('table', $header, $rows);
  return $output;
}

1 Ответ

0 голосов
/ 17 марта 2011
/**
 * Build a table of submitted values
 *
 * @param $select_mapping array Map select components to their value|label chocies
 * @param $values array Submitted form data
 * @return HTML of the themed table
 */
function _format_form_state($select_mapping, $values = array()) {
  $header = array(t('First'), t('Second'), t('Third'), t('Fourth'));
  $rows = array();

  foreach ($values as $cname => $cval) {
    $rows[] = array($cname, $cval, 0, $select_mapping);
  }

  return theme_table($header, $rows);
}

$ select_mapping должен быть первым аргументом в функции. Аргументу со значением по умолчанию не должно предшествовать аргумент без значения по умолчанию.

...