0

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) ?

Laky
  • 745
  • 2
  • 12
  • 25

1 Answers1

0

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);
}
Clive
  • 36,918
  • 8
  • 87
  • 113
  • Thanks, but in hidden value show and drupal throw a error Notice: Array to string conversion in drupal_attributes() – Laky Jan 07 '12 at 12:02
  • You must be passing an array to the function, just change it to pass a string instead and it will work – Clive Jan 07 '12 at 14:09
  • Thanks I managed to solve problem, just need to add &$form_state in form function "test_form($form, &$form_state, $name)" – Laky Jan 07 '12 at 17:27