2011-03-17 93 views
0

我試圖讓這段代碼只顯示有值的字段,任何沒有值的字段都不會被顯示出來。它似乎並沒有工作如何僅顯示具有值的字段,並隱藏沒有值的字段?

任何想法我做錯了什麼?

我簡單的測試形式是這裏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; 
} 
+0

任何人?............. :( – jeremy 2011-03-17 01:59:50

回答

0
/** 
* 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應該是在功能上的第一個參數。 帶有默認值的參數不應該以沒有默認值的參數開頭。

+0

Thankyou Dobeerman :) – jeremy 2011-03-20 23:01:19