次のコードを使用して、(DB から取得した配列に基づいて) フォーム要素を動的に生成しようとしています。
$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['values] 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 の値を取得します。