我使用下面的代碼試圖動態生成表單元素(基於從DB中檢索陣列上):Drupal的6表API不處理值
$form['stats'] = array
(
'#type' => 'fieldset',
'#title' => 'Statistics',
'#description' => 'Enter the data for the selected stat'
);
$arrStats = _stats_getStats($player_id);
if ($arrStats!=false)
{
foreach ($arrStats as $stat)
{
$arrVal = array();
$player_stats = _stats_getPlayerStats($player_id, $stat->sid);
if (!empty($player_stats))
$arrVal = $player_stats;
else
$arrVal = _stats_getPositionStats ($position->nid, $stat->sid);
$form['stats']['[nid:'.$stat->sid.']-1'] = array
(
'#type' => 'textfield',
'#title' => $stat->siname." - 1",
'#default_value' => $arrVal[0],
'#description' => 'Enter 1',
);
$form['stats']['[nid:'.$stat->sid.']-2'] = array
(
'#type' => 'textfield',
'#title' => $stat->siname." - 2",
'#default_value' => $arrVal[1],
'#description' => 'Enter 2',
);
}
}
生成form_state ['值] DPM看起來像這樣: (陣列,54個元件)
player-id (String, 2 characters) 74
[nid:90]-1 (String, 0 characters)
[nid:90]-2 (String, 0 characters)
[nid:89]-1 (String, 0 characters)
[nid:89]-2 (String, 0 characters)
[nid:80]-1 (String, 0 characters)
[nid:80]-2 (String, 0 characters)
[nid:79]-1 (String, 0 characters)
[nid:79]-2 (String, 0 characters)
[nid:78]-1 (String, 0 characters)
[nid:78]-2 (String, 0 characters)
[nid:91]-1 (String, 0 characters)
[nid:91]-2 (String, 0 characters)
[nid:92]-1 (String, 0 characters)
[nid:92]-2 (String, 0 characters)
[nid:93]-1 (String, 0 characters)
[nid:93]-2 (String, 0 characters)
[nid:94]-1 (String, 0 characters)
[nid:94]-2 (String, 0 characters)
[nid:95]-1 (String, 0 characters)
[nid:95]-2 (String, 0 characters)
[nid:98]-1 (String, 0 characters)
[nid:98]-2 (String, 0 characters)
[nid:96]-1 (String, 0 characters)
[nid:96]-2 (String, 0 characters)
[nid:97]-1 (String, 0 characters)
[nid:97]-2 (String, 0 characters)
[nid:99]-1 (String, 0 characters)
[nid:99]-2 (String, 0 characters)
[nid:141]-1 (String, 0 characters)
[nid:141]-2 (String, 0 characters)
[nid:143]-1 (String, 0 characters)
[nid:143]-2 (String, 0 characters)
[nid:146]-1 (String, 0 characters)
[nid:146]-2 (String, 0 characters)
[nid:147]-1 (String, 0 characters)
[nid:147]-2 (String, 0 characters)
[nid:149]-1 (String, 0 characters)
[nid:149]-2 (String, 0 characters)
[nid:150]-1 (String, 0 characters)
[nid:150]-2 (String, 0 characters)
[nid:151]-1 (String, 0 characters)
[nid:151]-2 (String, 0 characters)
[nid:144]-1 (String, 0 characters)
[nid:144]-2 (String, 0 characters)
[nid:145]-1 (String, 0 characters)
[nid:145]-2 (String, 0 characters)
[nid:148]-1 (String, 0 characters)
[nid:148]-2 (String, 0 characters)
所有動態生成的文本字段得到的值0,無論什麼I型放進去。
爲我節省了一天的調試時間。非常感謝你。 – user897452