Drupal 表单选项从循环填充
我想从循环中填充选择选项
$form['vote']['selected'] = array(
'#type' => 'select',
'#title' => 'Select',
'#name' => 'name',
);
foreach($loop as $row)
$form['vote']['selected']['#options'] = array($row->id => $row->name);
}
return $form;
需要帮助吗?
I want to populate select option from loop
$form['vote']['selected'] = array(
'#type' => 'select',
'#title' => 'Select',
'#name' => 'name',
);
foreach($loop as $row)
$form['vote']['selected']['#options'] = array($row->id => $row->name);
}
return $form;
Need some help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是执行此操作的标准方法:
您还可以查看
fetchAllKeyed
数据库查询方法,这是将数据从数据库获取到适合选择列表的键控数组的便捷快捷方式:上面的结果与上面的 foreach 循环完全相同。
This is the standard way to do it:
You might also look at the
fetchAllKeyed
method of the database query which is a handy shortcut to get data from the database into a keyed array suitable for select lists:The above will produce exactly the same as the
foreach
loop above.