简体   繁体   English

反复列出Drupal表单标题

[英]Iteratively list Drupal form titles

I am trying to list all #titles in a Drupal form module; 我正在尝试在Drupal表单模块中列出所有#titles however, I can't seem to get it to work. 但是,我似乎无法正常工作。

foreach ($form_values as $key => $value) {
   echo $form['myForm'][$key]['#title'];
}

The method above does not return anything. 上面的方法不返回任何内容。 I can list the $key values by doing the following: 我可以通过执行以下操作列出$key值:

foreach (...) {
   echo $key . ' ';
}

but I can't find a way to list the titles (eg, '#title' => t('Name') ) for each form input. 但是我找不到一种列出每种形式输入的标题(例如'#title' => t('Name') )的方法。

Any help? 有什么帮助吗? Thanks! 谢谢!

Your request a bit baffles me, but 您的要求让我感到困惑,但是

function print_title($form) {
  foreach (element_children($form) as $key) {
    print_title($form[$key]);
  }
  if (isset($form['#title'])) {
    // do something with your title
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM