Skip to main content
edited title
Link

Custom Multiple instances of same form in views doesdo not work properly

added 1241 characters in body
Source Link

I have a funny problem with Drupal 7 and Views.

I created programatically a simple form with two submit buttons (yes / no). This form is displayed on a full view of a node and when the 'yes' is pressed, it goes to a 'review' form which autofills the title with the one from the node. It works very well!

function mymodule_form($form, &$form_state,$nodeid) {
  global $user;
  $form['nodeid'] = array(
    '#type' => 'value',
    '#value' => $nodeid,
    '#access' => false,
  );

  $form['yes_button'] = array(
    '#type' => 'submit',
    '#value' => t('Yes'),
    '#submit' => array('yes_button_submit'),
  );

  $form['no_button'] = array(
    '#type' => 'submit',
    '#value' => t('No'),
    '#submit' => array('no_button_submit'),
  );
  return $form;
}

//Submit handlers
function yes_button_submit($form, &$form_state) {
    $nodeid = $form_state['values']['nodeid'];
    drupal_goto('node/add/review', array('query'=>array('id'=>$nodeid)));
}

I decided to add the buttons on the teasers that I display in a Views block. I call the form through a function which is called via a Global Php field. Here is the code inside the Global Php field, having added 'content: nid' as a hidden field in the view:

<?php
  $bling=mymodule_answers($row->nid);
  echo $bling;
?>

With the bit of code from mymodule_answers:

function mymodule_answers($nodeid) {
  $theform3 = drupal_get_form('mymodule_form',$nodeid);
  $output .= '<p class="text-center over">'.drupal_render($theform3).'</p>';

  return $output;
}

My problem is that if the view is something like this:

  • Node 1
  • Node 2
  • Node 3
  • Node 4

If I press 'yes' on any of the node teasers 2 to 4, then the review form is filled with the title of Node 1... meaning, the one at the top of the list!

I have thought about creating uniquely named forms, but I wouldn't know how to automatically generate the differently named submit handlers. Any ideas?

I have a funny problem with Drupal 7 and Views.

I created programatically a simple form with two submit buttons (yes / no). This form is displayed on a full view of a node and when the 'yes' is pressed, it goes to a 'review' form which autofills the title with the one from the node. It works very well!

I decided to add the buttons on the teasers that I display in a Views block. I call the form through a function which is called via a Global Php field. My problem is that if the view is something like this:

  • Node 1
  • Node 2
  • Node 3
  • Node 4

If I press 'yes' on any of the node teasers 2 to 4, then the review form is filled with the title of Node 1... meaning, the one at the top of the list!

I have thought about creating uniquely named forms, but I wouldn't know how to automatically generate the differently named submit handlers. Any ideas?

I have a funny problem with Drupal 7 and Views.

I created programatically a simple form with two submit buttons (yes / no). This form is displayed on a full view of a node and when the 'yes' is pressed, it goes to a 'review' form which autofills the title with the one from the node. It works very well!

function mymodule_form($form, &$form_state,$nodeid) {
  global $user;
  $form['nodeid'] = array(
    '#type' => 'value',
    '#value' => $nodeid,
    '#access' => false,
  );

  $form['yes_button'] = array(
    '#type' => 'submit',
    '#value' => t('Yes'),
    '#submit' => array('yes_button_submit'),
  );

  $form['no_button'] = array(
    '#type' => 'submit',
    '#value' => t('No'),
    '#submit' => array('no_button_submit'),
  );
  return $form;
}

//Submit handlers
function yes_button_submit($form, &$form_state) {
    $nodeid = $form_state['values']['nodeid'];
    drupal_goto('node/add/review', array('query'=>array('id'=>$nodeid)));
}

I decided to add the buttons on the teasers that I display in a Views block. I call the form through a function which is called via a Global Php field. Here is the code inside the Global Php field, having added 'content: nid' as a hidden field in the view:

<?php
  $bling=mymodule_answers($row->nid);
  echo $bling;
?>

With the bit of code from mymodule_answers:

function mymodule_answers($nodeid) {
  $theform3 = drupal_get_form('mymodule_form',$nodeid);
  $output .= '<p class="text-center over">'.drupal_render($theform3).'</p>';

  return $output;
}

My problem is that if the view is something like this:

  • Node 1
  • Node 2
  • Node 3
  • Node 4

If I press 'yes' on any of the node teasers 2 to 4, then the review form is filled with the title of Node 1... meaning, the one at the top of the list!

I have thought about creating uniquely named forms, but I wouldn't know how to automatically generate the differently named submit handlers. Any ideas?

edited tags
Link
Cyclonecode
  • 3.4k
  • 31
  • 47
added 67 characters in body
Source Link
Loading
Source Link
Loading