I am attempting to write a module that makes use of the forms api I currently have it tossed up on paste bin, but I'll add it here too...

The problem that I am running into comes when I hit the submit button for the form. I get a blank white screen and no results inserted into the db. I've spent the last couple of hours searching the handbook/forums for a solution and I just can't seem to figure this out... a trip to the irc dev channel didn't resolve it either...

If anyone has any insight that can get this resolved so I can move forward I would greatly appreciate it.

Thank you.

/* $Id$ */

/**
* Display help and module information
* @param section which section of the site we're displaying help
* @return help text for section
*/
function idkfa_help($section='') {

  $output = '';

  switch ($section) {
    case "admin/help#idkfa":
      $output = '<p>' .t("Game"). '</p>';
      break;
  }

  return $output;
} // function idkfa_help

/**
* Valid permissions for this module
* @return array An array of valid permissions for the idkfa module
*/
function idkfa_perm() {
  return array('access idkfa', 'administer idkfa');
} // function idkfa_perm()

function idkfa_menu() {

  $items = array();

  //use this entry to auto display a link in the user menu.
  $items[] = array(
    'path' => 'admin/settings/idkfa',
    'title' => t('idkfa settings'),
    'callback' => 'drupal_get_form',
    'callback arguments' => 'idkfa_admin',
    'access' => user_access('access administration pages'),
    'type' => MENU_NORMAL_ITEM,
   );

  //use this entry to handle access by url.
  $items[] = array(
    'path' => 'idkfa',
    'title' => t('idkfa'),
    'callback' => 'idkfa_all',
    'access' => user_access('access idkfa'),
    'type' => MENU_CALLBACK
  );

  return $items;
} // function idkfa_menu()

/**
* Create an administrator settings page
* @return ??
*/
function idkfa_admin() {

  $form['idkfa_maxplayers'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum number of players'),
    '#default_value' => variable_get('idkfa_maxplayers', 1000),
    '#size' => 4,
    '#maxlength' => 4,
    '#description' => t("The maximum number of players allowed per game.")
  );

  return system_settings_form($form);
} // function idkfa_admin()

function idkfa_all() {
  global $user;
  $my = idkfa_my();
  if(!$user->uid) {
    $output = "Not logged in, describe the game and that one should log in or create an account to join or enter the game.";
    return $output;
  } else {
    if ($my) {
      switch ($my->country_status) {
        case "0":
          $output = "Country is dead.  You must restart in order to continue playing.";
          return ($output);
          break;
        case "1":
          $form = array();
          $form['nav_tabs'] = array(
          '#type' => 'tabset',
          );
          // Displays as (#5)
          $form['nav_tabs']['tab1'] = array(
          '#type' => 'tabpage',
          '#title' => t('Build'),
          '#content' => include('idkfa.build.inc'),
          );
          // Displays as (#4)
          $form['nav_tabs']['tab2'] = array(
          '#type' => 'tabpage',
          '#title' => t('Cash'),
          '#content' => include('idkfa.cash.inc'),
          );
          // Displays as (#3)
          $form['nav_tabs']['tab3'] = array(
          '#type' => 'tabpage',
          '#title' => t('Explore'),
          '#content' => include('idkfa.explore.inc'),
          );
          // Displays as (#2)
          $form['nav_tabs']['tab4'] = array(
          '#type' => 'tabpage',
          '#title' => t('Status'),
          '#content' => include('idkfa.status.inc'),
          );
          // Displays as (#6)
          $form['nav_tabs']['tab5'] = array(
          '#type' => 'tabpage',
          '#title' => t('Research'),
          '#content' => include('idkfa.research.inc'),
          );
          // Displays as (#7)
          $form['nav_tabs']['tab6'] = array(
          '#type' => 'tabpage',
          '#title' => t('Market'),
          '#content' => include('idkfa.market.inc'),
          );
          // Displays as (#11)
          $form['nav_tabs']['tab7'] = array(
          '#type' => 'tabpage',
          '#title' => t('Exit Game'),
          '#content' => include('idkfa.exit.inc'),
          );
          // Displays as (#10)
          $form['nav_tabs']['tab8'] = array(
          '#type' => 'tabpage',
          '#title' => t('Search'),
          '#content' => include('idkfa.search.inc'),
          );
          // Displays as (#9)
          $form['nav_tabs']['tab9'] = array(
          '#type' => 'tabpage',
          '#title' => t('Scores'),
          '#content' => include('idkfa.scores.inc'),
          );
          // Displays as (#8)
          $form['nav_tabs']['tab10'] = array(
          '#type' => 'tabpage',
          '#title' => t('Military'),
          '#content' => include('idkfa.military.inc'),
          );
          // Displays as (#1)
          $form['nav_tabs']['tab11'] = array(
          '#type' => 'tabpage',
          '#title' => t('Main Menu'),
          '#content' => include('idkfa.main.inc'),
          );
          return tabs_render($form);
          break;
        }
    } else {
      return drupal_get_form('idkfa_create_country');
    }
  }
} // function idkfa_all()

function idkfa_create_country() {
  global $user;
  $form['country_name'] = array(
   '#type' => 'textfield',
   '#title' => t('Country Name'),
   '#size' => 60,
   '#maxlength' => 128,
   '#required' => TRUE,
  );
  $form['leader_name'] = array(
   '#type' => 'textfield',
   '#title' => t('Leader\'s Name'),
   '#value' => $user->name,
   '#size' => 60,
   '#maxlength' => 60,
   '#required' => TRUE,
  );
  $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
  return $form;
} // function idkfa_create_country()

function idkfa_create_country_submit($form_id, $form_values) {
  db_set_active('idkfa');
  db_query('INSERT INTO {country} (country_name, country_leader) VALUES (%d, %d)', $form_values['country_name'], $form_values['leader_name']);
  db_set_active();
  drupal_set_message(t('Set Message Here.'));
} // function idkfa_create_country_submit()

function idkfa_my() {
  global $user;
  db_set_active('idkfa');
  $my = db_fetch_object(db_query('SELECT * FROM {country} WHERE user_id = %d', $user->uid));
  db_set_active();
  return $my;
}

Comments

prakashp’s picture

I think the query in the function idkfa_create_country_submit($form_id, $form_values) should be

db_query("INSERT INTO {country} (country_name, country_leader) VALUES ('%s', '%s')", $form_values['country_name'], $form_values['leader_name']);

The country name and the leader name are strings and not integer.

About the page being blank, I would imagine you would redirect the user to the content you'd like to display
using the drupal_goto('path_to_your_page') at the end of the form_submit function.

Dixen’s picture

Okay, I made the change to the query and the results are still not making it into the db... I also added the drupal_goto() to the end of the function and it still white screens on me.

Any other suggestions?

Dixen’s picture

Okay, the white screen issue is php running out of memory. Apparently it was happening all over the site, not just the module being developed... Shiny in irc pointed that one out and once that module is disabled that problem is fixed.

The other problem was that the set_active was not actually firing off... I had a couple things configured wrong.

So, I'm assuming once I get the memory issues under control this will be working...