简体   繁体   中英

Setting value after returing form in Drupal

I generated form:

function test_form($form_state) {    

  $form['hidden'] = array(    

    '#type' => 'hidden',

  );   


  $form['submit'] = array(

    '#type' => 'submit',

    '#value' => 'Save'

  );   


  return $form;

}

After that I have a loop:

foreach($ea as $name){



$test_form = drupal_get_form('test_form');



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



}

It should somehow arrange that every time when do the loop, hidden in test_form take value of $name->name? Is it possible to do something with form_set_value($element, $value, &$form_state) ?

You'd be best off passing the name to the function as a parameter:

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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