Drupal Form API - 从数据库填充字段
我希望用数据库中的记录填充 drupals 表单 api 字段。
with:
function mytopfive() {
$form['mytop_header'] = array(
'#type' => 'markup',
'#value' => t('<h2>Your favourite Jobs</h2>'),
);
$result = mysql_query('SELECT * FROM topfive WHERE uid = 1 ORDER BY order_value ASC');
while ($node = db_fetch_object($result)) {
$rid = $node->rid;
$order = $node->order_value;
$title= $node->title;
$form['rid'][$node->rid] = array(
'#type' => 'textfield',
'#size' => 2,
'#maxlength' => 1,
'#default_value' => $rid,
);
$form['job_name'][$node->rid] = array(
'#type' => 'textfield',
'#title' => t('To'),
'#size' => 40,
'#maxlength' => 42,
'#value' => $title,
);
$form['job_order'][$node->rid] = array(
'#type' => 'textfield',
'#size' => 2,
'#maxlength' => 1,
'#default_value' => $order,
);
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
return $form;
}
它返回数组。
我觉得答案是 foreach 循环。
非常感谢任何帮助。
Im looking to populate drupals form api fields with records from the database.
with:
function mytopfive() {
$form['mytop_header'] = array(
'#type' => 'markup',
'#value' => t('<h2>Your favourite Jobs</h2>'),
);
$result = mysql_query('SELECT * FROM topfive WHERE uid = 1 ORDER BY order_value ASC');
while ($node = db_fetch_object($result)) {
$rid = $node->rid;
$order = $node->order_value;
$title= $node->title;
$form['rid'][$node->rid] = array(
'#type' => 'textfield',
'#size' => 2,
'#maxlength' => 1,
'#default_value' => $rid,
);
$form['job_name'][$node->rid] = array(
'#type' => 'textfield',
'#title' => t('To'),
'#size' => 40,
'#maxlength' => 42,
'#value' => $title,
);
$form['job_order'][$node->rid] = array(
'#type' => 'textfield',
'#size' => 2,
'#maxlength' => 1,
'#default_value' => $order,
);
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
return $form;
}
it returns Array.
I feel the answer is a foreach loop.
any help much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当你说:
“it returns Array”
...是Echo的输出,还是drupal页面的输出?如果是后者,您需要从 drupal_get_form 调用此函数才能正确呈现表单。因此,在您的情况下,您需要一个带有
'pagecallback' => 的菜单项'drupal_get_form'
和'页面参数' =>数组('mytop Five')
。如果这没有意义,请告诉我:)
When you say:
"it returns Array"
... is that the output from an Echo, or the output to the drupal page?if its the latter, you need to be calling this function from
drupal_get_form
in order to have the form rendered correctly. so in your case you need a menu item with'page callback' => 'drupal_get_form'
and'page arguments' => array('mytopfive')
.Let me know if that makes no sense :)