0

我生成了表格:

function test_form($form_state) {    

  $form['hidden'] = array(    

    '#type' => 'hidden',

  );   


  $form['submit'] = array(

    '#type' => 'submit',

    '#value' => 'Save'

  );   


  return $form;

}

之后我有一个循环:

foreach($ea as $name){



$test_form = drupal_get_form('test_form');



$output .= $name->name . drupal_render($test_form);



}

它应该以某种方式安排每次执行循环时,隐藏在 test_form 中的值为 $name->name?可以用 form_set_value($element, $value, &$form_state) 做点什么吗?

4

1 回答 1

0

您最好将名称作为参数传递给函数:

function test_form($form_state, $name) {    

  $form['hidden'] = array(    

    '#type' => 'hidden',
    '#value' => $name
  ); 

  //...
}

foreach ($ea as $name) {
  $test_form = drupal_get_form('test_form', $name->name);

  $output .= $name->name . drupal_render($test_form);
}
于 2012-01-06T13:15:18.390 回答