HI @all,

I'm not sure if I do something wrong, or if Drupal 6.x has a bug...

I'm building a little form with the FAPI that is attached to a node's content via drupal_get_form('my_form_id'). Everything works fine, but when several nodes with this form are on the same page (e.g. on the front page "node") the values in $form_state['values'] differ from the $_POST values. The $_POST values are correct, but int the $form_state['values'] array the values of the first form on the page are taken and not the ones from the form submitted (even though in the $form_state['clicked_button']['#post'] all values are correct).

Does anyone experience the same problem, or do you have any idea what's going wrong?

I'd appreciate your help & thanx in advance



mooffie’s picture

This isn't a bug.

You have several forms on the page.

When the user submits a form, Drupal tries to figure out which Drupal form this submission belongs to. It does this by inspecting the $_POST['form_id'] variable. This is a hidden HTML field, included with each form, which is equal to the Drupal form id. Since all your forms have the same ID ('my_form_id' in your case), Drupal cannot distinguish between them; it always thinks it was the first form that was submitted.

One way to solve this is to give each form a different form id. For example, instead of drupal_get_form('my_form_id'), do drupal_get_form("my_form_id_$nid"). But, of course, you don't have any function named my_form_id_24315, so you'll have to implement hook_forms() to direct FAPI to the "my_form_id" function. It's all explained in api.drupal.org. Something along of:

function mymodule_forms($args) {
  $form_id = $args[0];
  if (preg_match('/^my_form_id_\d+$/', $form_id)) {
     $forms[$form_id]['callback'] = 'my_form_id';
     reutrn $forms;
// Code not tested. Debugging left as excercise for reader.

Note: since no "my_form_id_24315_submit" function exists either, make sure the form has explicit $form['#submit'] = '...' somewhere.

hctom’s picture

... you are right! I don't know why I forgot about that.. This solved the problem...

So thanx very much & keep up the good work :-)



KingMoore’s picture

Is there a downside to just using the data from [clicked_button][#post] ?