0

I've been search results for hours but cannot find an answer to my problem.

I want to show a list using theme("table",...); inside my table, there's a column of buttons, which each functions as deleting the record for this row. Therefore, I did something like this:

foreach($person_list as $pyid => $record){
  $render_ele = array('remove'.$pyid => array(
      '#type' => "submit",
      "#value"=> "remove",
      '#submit' => array('shms_cca_form_remove_person_from_group'),
      "#limit_validation_errors"  => array(),
      "#attributes" => array("pyid" => $pyid,'action' => "remove"),
    ));
  $rows[] = array(
    $record['full_name'], // full name
    $record['matric_no'],  // matric no
    $record['room_number'], // room number
    $record['position_name'],
    is_numeric($record['cca_points'])?$record['cca_points']:"Not Assigned Yet",
    drupal_render_children($render_ele),
  );
};

However, when I clicked on the button, the submit function I've defined is not called (it called the default submit function instead).

When I try to add another default button into my form like this:

$form += array(
  'nani' => array(
    '#type' => "submit",
      "#value"=> "remove",
      '#submit' => array('shms_cca_form_remove_person_from_group'),
      "#limit_validation_errors"  => array(),
  ),

Both this button and my old-not-functioning submit button works.

I therefore conclude that it's a JavaScript problem... possibly some JavaScript is not included when I call the drupal_render by myself.

Could anyone help on how to solve this problem? Thanks a lot.

Update: I called drupal_render, because I want to pass the rendered result to rows[] so that I can put these elements inside a table, like this:

$render_ele = array('remove'.$pyid => array(
      '#type' => "submit",
      "#value"=> "remove",
      '#submit' => array('shms_cca_form_remove_person_from_group'),
      "#limit_validation_errors"  => array(),
      "#attributes" => array("pyid" => $pyid,'action' => "remove"),
    ));

$rows[] = array(
  $record['full_name'], // full name
  $record['matric_no'],  // matric no
  $record['room_number'], // room number
  drupal_render($option),
);
return array(
"person_list" => array(
  '#type' => 'fieldset',
  "#title"=> t("Group Members"),
  '#collapsible'  => TRUE,
  "#collapsed"  => FALSE,
  "#children"   => theme("table",array('header'=>$header,"rows"=>$rows)).$add_member_str,
  '#weight'     => 10,
),

);

1 Answer 1

0

Are you returning those $render_elem from your form function, when drupal_get_form calls that form id callback? Because i see you call drupal_render_children, but drupal need to know about it in form of form api array. drupal_get_form expecting you return from your form_id function form api array of form elements, so it can do some operation like checking, if current request is POST and contains form_id of your form and some name of submit button.

EDIT: Try add all submit buttons to your form array, but set their property #printed => true, so they won't be rendered, but drupal will be notified about those buttons and can run your submit functions.

2
  • Hi thanks for the reply. I didn't put return these elements from my form function, but used the rendered result directly (see my update at the end of my original post). So I should use a theme function to achieve similar effects (putting a button / form_api into a table)?
    – songyy
    Jul 21, 2012 at 18:35
  • If you didn't return that elements, drupal cannot know about that elements, so can't run your submit functions man. You must return all the form elements.
    – Krab
    Jul 21, 2012 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.