after theme a form with Tapir, drupal form submit function is not called?

Posts: 24
Joined: 02/28/2008

After using Tapir to theme a form, the form submit function is not called. So where should I intercept the submit? I must be missing something.

I am testing with http://www.ubercart.org/docs/tapir/3000/example_6_theme_form_tapir.

I added

<?php
function tapirtest_example_6_form_submit($form, &$form_values) {
 
 
drupal_set_message(t('blah balh tapirtest_example_6_form_submit'));

}
?>

However, if I have theme_tapirtest_example_6_form(), then the submit function is bypassed. If I remove theme_tapirtest_example_6_form(), the submit function will be called.

Thanks for any help.

Posts: 5620
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

What happens if you change:

<?php
function tapirtest_example_table_6($op, $form) {
?>

To:

<?php
function tapirtest_example_table_6($op, &$form) {
?>

Puzzled

Posts: 24
Joined: 02/28/2008

vow! this is incredible!! It's real time response!

I tried it, and it fixed the problem!!!

May be someone need to update sample 6 in that link.

Thanks a bunch!

Posts: 5620
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Will do. Thanks for working through the docs and posting your feedback. Eye-wink

Posts: 24
Joined: 02/28/2008

Hi Ryan,

Sorry to bug you guys again. I am afraid the problem still persists. I thought it was working after the change, but I tried many times afterwards, it appears the problem is still there.

I am pasting my code as-is. If I remove theme function then the submit will be called. Otherwise, it skips the submit function.

Hope I'm not overlooking something obvious.

thanks.

<?php
function tapirtest_menu($may_cache) {
// temp code for test
   
$items[] = array(
     
'path' => 'tapirtest/example_submit',
     
'title' => t('Test submit, Example 6: Theme a Form with TAPIr'),
     
'callback' => 'drupal_get_form',
     
'callback arguments'=>'tapirtest_example_6_form',
     
'access' => user_access('access content'),
     
'type' => MENU_CALLBACK,
    );

  return
$items;
}

function
tapirtest_example_6() {
 
$output = '<p>'. drupal_get_form('tapirtest_example_6_form') .'</p>';
  return
$output;
}

function
tapirtest_example_6_form_submit($form, &$form_values) {   
 
$x = 1;
 
form_set_error("blah blah");
}

function
tapirtest_example_6_form() {
 
$form['songs'] = array('#tree' => TRUE);
 
$result = db_query("SELECT * FROM {tapirtest_example_5}");
  while (
$row = db_fetch_object($result)) {
   
$form['songs'][$row->song_id]['song'] = array(
     
'#value' => $row->song,
    );
   
$form['songs'][$row->song_id]['artist'] = array(
     
'#type' => 'textfield',
     
'#size' => 16,
     
'#default_value' => $row->artist,
    );
   
$form['songs'][$row->song_id]['album'] = array(
     
'#type' => 'textfield',
     
'#size' => 32,
     
'#default_value' => $row->album,
    );
  }
 
$form['submit'] = array(
   
'#type' => 'submit',
   
'#value' => t('Submit'),
  );
  return
$form;
}

function
remove_theme_tapirtest_example_6_form($form) {
 
$output = '<p>'. tapir_get_table('tapirtest_example_table_6', $form)
          .
drupal_render($form['submit']) .'</p>';
  return
$output;
}

function
tapirtest_example_table_6($op, &$form) {
  switch (
$op) {
    case
'fields':
     
$fields[] = array('name' => 'song', 'title' => t('Song'), 'weight' => 0, 'enabled' => TRUE);
     
$fields[] = array('name' => 'artist', 'title' => t('Artist'), 'weight' => 1,
                      
'enabled' => TRUE, 'locked' => TRUE);
     
$fields[] = array('name' => 'album', 'title' => t('Album'), 'weight' => 2,
                      
'enabled' => TRUE, 'locked' => TRUE);
      return
$fields;
    case
'data':
      foreach (
element_children($form['songs']) as $i) {
       
$data['song'][] = drupal_render($form['songs'][$i]['song']);
       
$data['artist'][] = drupal_render($form['songs'][$i]['artist']);
       
$data['album'][] = drupal_render($form['songs'][$i]['album']);
      }
      return
$data;
  }
}
?>

Posts: 34
Joined: 02/04/2008

I think in themeing forms you need to output:
drupal_render($form);
at the end of your form.

Just try inserting that at the end of your theme function. It does some sort of voodoo and tells the magic form pixies to make the form work.
I've never fully understood it.

So try:

function remove_theme_tapirtest_example_6_form($form) {
  $output = '<p>'. tapir_get_table('tapirtest_example_table_6', $form)
          . drupal_render($form['submit']) .'</p>';
  $output .= drupal_render($form);
  return $output;
}

Posts: 24
Joined: 02/28/2008

That's a great catch.

I recall now that I actually changed that line when I was testing it. Originally, I had some problem with that line, because it was duplicating the form after the table. Now I don't know why it doesn't do that anymore.

So I added that line back, it's working. Thanks a lot.

BTW, for other readers benefit, please take out that 'remove_' part in remove_theme_tapirtest_example_6_form() function name, I added that for my debugging purpose.