Drupal 2 blocks same form function with different output not working I have dynamically created some blocks depending on how many entries I have in the database:

    function my_module_block_info() {
        $result_set = db_select('my_products', 'products')
            -&gt;fields('products', array('pid', 'name'))
            -&gt;execute();

        $blocks = array();

        foreach($result_set as $product) {
            $blocks['my_product_' . $product-&gt;pid] = array(
              'info' =&gt; ('My Product ' . $product-&gt;name)
            );
        }

        return $blocks;
    }

    function my_module_block_view($delta = '') {
        $pieces = explode('_', $delta);
        $pid = $pieces[2];
        $product = db_select('my_products', 'products')
            -&gt;fields('products')
            -&gt;condition('products.pid', $pid, '=')
            -&gt;execute()
            -&gt;fetchObject();

        $block['subject'] = $product-&gt;name;
        $block['content'] = my_module_block_content($product);
        return $block;
    }

function my_module_block_content(&amp;$product) {
    $form = drupal_get_form('my_module_block_form', $product);

    $output = '&lt;p&gt;' . $product-&gt;price . '&lt;/p&gt;';

    $output .= drupal_render($form);

    return $output;
}

function my_module_block_form($form, &amp;$formstate, $product) {
    $form['submit_product] = array(
      '#type' =&gt; 'image_button',
      '#button_type' =&gt; 'submit',
      '#src' =&gt; base_path() . path_to_theme() . '/images/buy.gif',
    );
    $form['product_name'] = array(
      '#type' =&gt; 'hidden',
      '#value' =&gt; $product-&gt;name,
);
    return $form;
}


My problem is that when I have 2 blocks with different products on one page, the submit function for the second block displayed has the value of $form['product_name']['#value'] equal to the first block, which is an entirely different product. What am I doing wrong?
I would suggest to prefix the form array with your product ID (I guess $product->pid or something like this) :

function my_module_block_form($form, &amp;$formstate, $product) {
    $form[$product-&gt;pid]['submit_product] = array(
      '#type' =&gt; 'image_button',
      '#button_type' =&gt; 'submit',
      '#src' =&gt; base_path() . path_to_theme() . '/images/buy.gif',
    );
    $form[$product-&gt;pid]['product_name'] = array(
      '#type' =&gt; 'hidden',
      '#value' =&gt; $product-&gt;name,
    );
    return $form;
}


Then the fields shouldn't be overwritten.