Okay, been working on a new module as a learning the drupal api exercise and I am finally down to only one problem, I think.
I'm using xampp v1.6.3a with php 5.2.3 and mysql 5.0.45... I'm using firefox 2.0. Below is a copy of the module code that I am using as my learning experience.
The problem currently is that every time a form of any kind, anywhere on the test site is submitted I get the White Screen of Death, I put my cursor in the address bar of the browser and hit return to load the page and it'll come up fine as it should (or at least as one would expect). If I disable the module, everything works like it should. Re-enable the module, broken again.
This can't possibly be a memory problem as I put the memory allocation on my test server up to 512MB...
Now, for some trouble shooting steps I have already taken:
1) I put the module up on a production site to see if it was someone linked to server conf, no luck. Same issue, but I do actually get an error on the production site, however I'm not sure it's relevant to the problem as I have output buffering turned on on my test server.
warning: Cannot modify header information - headers already sent by (output started at /home/crimson/public_html/sites/all/modules/idkfa/idkfa.module:1) in /home/crimson/public_html/includes/common.inc on line 309.
2) I completely blanked out the .module file so as to have absolutely nothing in it... the site works fine. Putting *anything* back into that file causes the error to occur again. I tired only putting in the opening php tag, and even just and opening html tag.
3) To reiterate, I raised the php memory limit to 512MB.
I have gone through 15 pages of posts after searching for "white Screen of Death" and tried just about everything I found in there... I do not think the problem is specifically server related, and may not be "drupal" related other than the code I am using.
Ultimately the one thing I haven't tried, which I will do now is that that I am using 2 dbs for this module... I figured it would be a better exercise of the api. I had an issue with the 2nd db not being recognized and do not remember encountering this problem before getting that working... Perhaps that might jog someone's thought process in helping me get this resolved.
Thank you for your time...
/* $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 (#1)
$form['nav_tabs']['tab1'] = array(
'#type' => 'tabpage',
'#title' => t('Main Menu'),
'#weight' => '-10',
'#content' => include('idkfa.main.inc'),
);
// Displays as (#2)
$form['nav_tabs']['tab2'] = array(
'#type' => 'tabpage',
'#title' => t('Status'),
'#weight' => '-9',
'#content' => include('idkfa.status.inc'),
);
// Displays as (#3)
$form['nav_tabs']['tab3'] = array(
'#type' => 'tabpage',
'#title' => t('Explore'),
'#weight' => '-8',
'#content' => include('idkfa.explore.inc'),
);
// Displays as (#4)
$form['nav_tabs']['tab4'] = array(
'#type' => 'tabpage',
'#title' => t('Cash'),
'#weight' => '-7',
'#content' => include('idkfa.cash.inc'),
);
// Displays as (#5)
$form['nav_tabs']['tab5'] = array(
'#type' => 'tabpage',
'#title' => t('Build'),
'#weight' => '-6',
'#content' => include('idkfa.build.inc'),
);
// Displays as (#6)
$form['nav_tabs']['tab6'] = array(
'#type' => 'tabpage',
'#title' => t('Research'),
'#weight' => '-5',
'#content' => include('idkfa.research.inc'),
);
// Displays as (#7)
$form['nav_tabs']['tab7'] = array(
'#type' => 'tabpage',
'#title' => t('Market'),
'#weight' => '-4',
'#content' => include('idkfa.market.inc'),
);
// Displays as (#8)
$form['nav_tabs']['tab8'] = array(
'#type' => 'tabpage',
'#title' => t('Military'),
'#weight' => '-3',
'#content' => include('idkfa.military.inc'),
);
// Displays as (#9)
$form['nav_tabs']['tab9'] = array(
'#type' => 'tabpage',
'#title' => t('Scores'),
'#weight' => '-2',
'#content' => include('idkfa.scores.inc'),
);
// Displays as (#10)
$form['nav_tabs']['tab10'] = array(
'#type' => 'tabpage',
'#title' => t('Search'),
'#weight' => '-1',
'#content' => include('idkfa.search.inc'),
);
// Displays as (#11)
$form['nav_tabs']['tab11'] = array(
'#type' => 'tabpage',
'#title' => t('Exit Game'),
'#weight' => '-0',
'#content' => include('idkfa.exit.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'),
'#default_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) {
global $user;
db_set_active('idkfa');
db_query("INSERT INTO {country} (user_id, country_name, country_leader) VALUES (%d, '%s', '%s')", $user->uid, $form_values['country_name'], $form_values['leader_name']);
db_set_active();
drupal_set_message(t('Set Message Here.'));
return 'idkfa';
} // 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;
} // function idkfa_my
Comments
2 dbs, not the problem.
I just copied the table for this module into my default database, removed the db array from settings.php, and updated the code to reflect only using 1 db and I still get the WSoD when submitting forms.
Resolution
Okay, popped into the irc channel #drupal for some help on this one... and Chx and Dww nailed it down for me. After truncating the watchdog table and "trying" again I got the same error as above (on my test server this time).
Chx was kind enough to point out that:
(chx): PHP told you in no uncertain terms
As it turns out there was whitespace at the beginning of the file which was causing PHP to bomb (point out by the error in which "output started at /home/crimson/public_html/sites/all/modules/idkfa/idkfa.module:1" I dismissed the :1 as a line number because ti didn't say "Line 1"). I copied the contents of the file into a newly created file, deleted the old one and viola, it worked.
6 hours worth of head pounding against the wall and Chx nails it down in about 30 seconds. *sighs* I wanna be like Chx when I grow up. :)
Chx, Dww... thank you much for the help guys, +2 for #drupal.