Page 1 of 1

UPDATED:Javascript function call loading intermitently in IE

Posted: Wed May 05, 2010 10:46 pm
by quakefiend420
UPDATE: I've figured out that the javascript function that creates the search boxes is intermittently failing to load, if I wait about 45 seconds in between searches it works properly every single time. Any ideas?

I have put together a database and using a tool called PHPmyEdit have put together a simple front end that will query a single MySQL table. My problem is, the search function is broken in all versions of IE, works just fine in Opera, Chrome, and Firefox. I have been searching for hours to an answer to my problem, and have found none. I am not a professional coder by any means, just a geek who likes to tinker, and can often figure things out on his own after some trial and error and research. I am having fun learning about PHP and SQL, however I am at my wit's end here, and am really hoping that the community here holds the key to my problems.

Here are the symptoms, when calling the Search function in IE, it will come up, however executing a search causes the entry fields to disappear and the search most often fails. If I try to bring them back up, they do not appear unless I wait for 45 seconds or so, then I can get them to come back. I can still sort by varying fields, but the search function is completely broken in IE. Let me post the code I'm using, perhaps someone here can point me in the right direction.

Here is the main page:

Code: Select all

</style>
</head>
<body>
<h3>Header</h3>
<?php

// MySQL host name, user name, password, database, and table
$opts['hn'] = 'localhost';
$opts['un'] = 'user';
$opts['pw'] = 'password';
$opts['db'] = 'mydatabase';
$opts['tb'] = 'mytable';

// Name of field which is the unique key
$opts['key'] = 'primarykey';

// Type of key field (int/real/string/date etc.)
$opts['key_type'] = 'string';

// Sorting field(s)
$opts['sort_field'] = array('primarykey');

// Number of records to display on the screen
// Value of -1 lists all records in a table
$opts['inc'] = 15;

// Options you wish to give the users
// A - add,  C - change, P - copy, V - view, D - delete,
// F - filter, I - initial sort suppressed
$opts['options'] = 'F';

// Number of lines to display on multiple selection filters
$opts['multiple'] = '4';

// Navigation style: B - buttons (default), T - text links, G - graphic links
// Buttons position: U - up, D - down (default)
$opts['navigation'] = 'TD';

// Display special page elements
$opts['display'] = array(
	'form'  => true,
	'query' => false,
	'sort'  => false,
	'time'  => true,
	'tabs'  => false,
);

// Set default prefixes for variables
$opts['js']['prefix']               = 'PME_js_';
$opts['dhtml']['prefix']            = 'PME_dhtml_';
$opts['cgi']['prefix']['operation'] = 'PME_op_';
$opts['cgi']['prefix']['sys']       = 'PME_sys_';
$opts['cgi']['prefix']['data']      = 'PME_data_';

/* Get the user's default language and use it if possible or you can
   specify particular one you want to use. Refer to official documentation
   for list of available languages. */
$opts['language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'] . 'Unicode';

/* Table-level filter capability. If set, it is included in the WHERE clause
   of any generated SELECT statement in SQL query. This gives you ability to
   work only with subset of data from table.

$opts['filters'] = "column1 like '%11%' AND column2<17";
$opts['filters'] = "section_id = 9";
$opts['filters'] = "PMEtable0.sessions_count > 200";
*/

/* Field definitions
   
Fields will be displayed left to right on the screen in the order in which they
appear in generated list. Here are some most used field options documented.

['name'] is the title used for column headings, etc.;
['maxlen'] maximum length to display add/edit/search input boxes
['trimlen'] maximum length of string content to display in row listing
['width'] is an optional display width specification for the column
          e.g.  ['width'] = '100px';
['mask'] a string that is used by sprintf() to format field output
['sort'] true or false; means the users may sort the display on this column
['strip_tags'] true or false; whether to strip tags from content
['nowrap'] true or false; whether this field should get a NOWRAP
['select'] T - text, N - numeric, D - drop-down, M - multiple selection
['options'] optional parameter to control whether a field is displayed
  L - list, F - filter, A - add, C - change, P - copy, D - delete, V - view
            Another flags are:
            R - indicates that a field is read only
            W - indicates that a field is a password field
            H - indicates that a field is to be hidden and marked as hidden
['URL'] is used to make a field 'clickable' in the display
        e.g.: 'mailto:$value', 'http://$value' or '$page?stuff';
['URLtarget']  HTML target link specification (for example: _blank)
['textarea']['rows'] and/or ['textarea']['cols']
  specifies a textarea is to be used to give multi-line input
  e.g. ['textarea']['rows'] = 5; ['textarea']['cols'] = 10
['values'] restricts user input to the specified constants,
           e.g. ['values'] = array('A','B','C') or ['values'] = range(1,99)
['values']['table'] and ['values']['column'] restricts user input
  to the values found in the specified column of another table
['values']['description'] = 'desc_column'
  The optional ['values']['description'] field allows the value(s) displayed
  to the user to be different to those in the ['values']['column'] field.
  This is useful for giving more meaning to column values. Multiple
  descriptions fields are also possible. Check documentation for this.
*/

$opts['fdd']['value1'] = array(
  'name'     => 'value1',
  'select'   => 'T',
  'options'  => 'AVCPDR', // auto increment
  'maxlen'   => 11,
  'default'  => '0',
  'sort'     => true
);
$opts['fdd']['value2'] = array(
  'name'     => 'value2',
  'select'   => 'T',
  'maxlen'   => 255,
  'sort'     => true
);
$opts['fdd']['value3'] = array(
  'name'     => 'value3,
  'select'   => 'T',
  'maxlen'   => 255,
  'sort'     => true
);
$opts['fdd']['value4] = array(
  'name'     => 'value4,
  'select'   => 'T',
  'maxlen'   => 255,
  'sort'     => true
);
$opts['fdd']['value5'] = array(
  'name'     => 'value5',
  'select'   => 'T',
  'maxlen'   => 255,
  'sort'     => true
);
$opts['fdd']['value6] = array(
  'name'     => 'value6',
  'select'   => 'T',
  'maxlen'   => 255,
  'sort'     => true
);

// Now important call to phpMyEdit 
require_once 'extensions/phpMyEdit-report.class.php'; 
new phpMyEdit($opts);

?>


</body>
</html>
Here is the extension called to generate the report:

Code: Select all

<?php


require_once dirname(__FILE__).'/../phpMyEdit.class.php';

class phpMyEdit_report extends phpMyEdit
{

	function phpMyEdit_report($opts) /* {{{ */
	{
		$opts['options'] = 'L';
		$execute = 1;
		isset($opts['execute']) && $execute = $opts['execute'];
		$opts['execute'] = 0;
		parent::phpMyEdit($opts);
		$execute && $this->execute();
	} /* }}} */

	function make_language_labels($language) /* {{{ */
	{
		$ret = parent::make_language_labels($language);
		strlen($ret['Make report'])        <= 0 && $ret['Make report']        = 'Make report';
		strlen($ret['Select fields'])      <= 0 && $ret['Select fields']      = 'Select fields';
		strlen($ret['Records per screen']) <= 0 && $ret['Records per screen'] = 'Records per screen';
		return $ret;
	} /* }}} */

	function get_cgi_cookie_var($name, $default_value = null) /* {{{ */
	{
		$ret = $this->get_cgi_var($name, null);
		if ($ret === null) {
			global $HTTP_COOKIE_VARS;
			$ret = @$HTTP_COOKIE_VARS[$name.'_'.$this->tb.'_cookie'];
			if (! isset($ret)) {
				$ret = $default_value;
			}
		}
		return $ret;
	} /* }}} */

	function display_list_table_buttons($total_recs, $position) /* {{{ */
	{	/* This is mostly copy/paste from core class. */
		$listall = $this->inc <= 0; // Are we doing a listall?
		echo '<table class="',$this->getCSSclass('navigation', $position),'">',"\n";
		echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n";
		echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n";
		echo '<input class="',$this->getCSSclass('fields-select', $position);
		echo '" type="submit" name="fields_select" value="',$this->labels['Select fields'],'">&nbsp;';
		// Note that <input disabled isn't valid HTML, but most browsers support it
		$disabled = ($this->fm > 0 && ! $listall) ? '' : ' disabled';
		echo '<input',$disabled,' class="',$this->getCSSclass('prev', $position);
		echo '" type="submit" name="',ltrim($disabled),'prev" value="',$this->labels['Prev'],'">&nbsp;';
		$disabled = ($this->fm + $this->inc < $total_recs && ! $listall) ? '' : ' disabled';
		echo '<input',$disabled,' class="',$this->getCSSclass('next', $position);
		echo '" type="submit" name="',ltrim($disabled),'next" value="',$this->labels['Next'],'">';
		// Message is now written here
		echo '</td>',"\n";
		if (strlen(@$this->message) > 0) {
			echo '<td class="',$this->getCSSclass('message', $position),'">',$this->message,'</td>',"\n";
		}
		// Display page and records statistics
		echo '<td class="',$this->getCSSclass('stats', $position),'">',"\n";
		if ($listall) {
			echo $this->labels['Page'],':&nbsp;1&nbsp;',$this->labels['of'],'&nbsp;1';
		} else {
			echo $this->labels['Page'],':&nbsp;',($this->fm / $this->inc) + 1;
			echo '&nbsp;',$this->labels['of'],'&nbsp;',max(1, ceil($total_recs / abs($this->inc)));
		}
		echo '&nbsp; ',$this->labels['Records'],':&nbsp;',$total_recs;
		echo '</td></tr></table>',"\n";
	} /* }}} */

	function display_report_selection_buttons($position) /* {{{ */
	{
		echo '<table class="',$this->getCSSclass('navigation', $position),'">',"\n";
		echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n";
		echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n";
		echo '<input class="',$this->getCSSclass('make-report', $position);
		echo '" type="submit" name="prepare_filter" value="',$this->labels['Make report'],'">',"\n";
		echo '</td></tr></table>',"\n";
	} /* }}} */

	function get_select_fields_link() /* {{{ */
	{
		$link = '<a href="'.htmlspecialchars($this->page_name).'?fields_select=1';
		for ($i = 0; $i < count($table_cols); $i++) {
			$varname = 'qf'.$i;
			$value   = $this->get_cgi_cookie_var($varname);
			if (! empty($value)) {
				$link .= htmlspecialchars(
						'&'.rawurlencode($varname).
						'='.rawurlencode($value));
			}
		}
		$link .= htmlspecialchars($this->cgi['persist']);
		$link .= '">'.$this->labels['Select fields'].'</a>';
		return $link;
	} /* }}} */

	function execute() /* {{{ */
	{
		global $HTTP_GET_VARS;
		global $HTTP_POST_VARS;

		/*
		 * Extracting field names
		 */

		$table_cols     = array();
		$all_table_cols = array();

		if ($this->connect() == false) {
			return false;
		}
		$query_parts = array(
				'type'   => 'select',
				'select' => '*',
				'from'   => $this->tb,
				'limit'  => '1');
		$result = $this->myquery($this->get_SQL_query($query_parts), __LINE__);
		$all_table_cols = array_keys(@mysql_fetch_array($result, MYSQL_ASSOC));
		if (count($all_table_cols) <= 0) {
			$this->error('database fetch error');
			return false;
		}
		foreach (array_keys($this->fdd) as $field_name) {
			if (preg_match('/^\d*$/', $field_name))
				continue;
			if (($idx = array_search($field_name, $all_table_cols)) !== false)
				$table_cols[$field_name] = mysql_field_len($result, $idx);
		}
		@mysql_free_result($result);
		unset($all_table_cols);

		/*
		 * Preparing variables
		 */

		$fields_select  = $this->get_cgi_var('fields_select');
		$filter         = $this->get_cgi_var('filter');
		$prepare_filter = $this->get_cgi_var('prepare_filter');
		$this->inc      = intval($this->get_cgi_cookie_var('inc'));
		$force_select   = true;
		$none_displayed = true;
		$expire_time    = time() + (3600 * 24 * 30 * 12 * 5); // five years
		$headers_sent   = @headers_sent();

		foreach (array_merge(array('@inc'), array_keys($table_cols)) as $col) {
			$varname = ($col[0] == '@' ? substr($col, 1) : 'have_'.$col);
			if (isset($HTTP_POST_VARS[$varname]) || isset($HTTP_GET_VARS[$varname])) {
				$value = $HTTP_POST_VARS[$varname];
				if (isset($HTTP_GET_VARS[$varname])) {
					$value = $HTTP_GET_VARS[$varname];
				}
				if ($varname != 'inc' && ! empty($value)) {
					$force_select = false;
				}
				$headers_sent || setcookie($varname.'_'.$this->tb.'_cookie', $value, $expire_time);
				$this->cgi['persist'] .= '&'.urlencode($varname);
				$this->cgi['persist'] .= '='.urlencode($value);
			} else {
				$headers_sent || setcookie($varname.'_'.$this->tb.'_cookie', '', time() - 10000);
			}
		}

		$i = -1;
		foreach (array_keys($this->fdd) as $key) {
			$i++;
			if (preg_match('/^\d*$/', $key))
				continue;
			$varname = 'have_'.$key;
			$value   = @$this->get_cgi_cookie_var($varname, '');
			$options = @$value ? 'LV' : '';
			$this->fdd[$i]['options']   = $options;
			$this->fdd[$key]['options'] = $options;
			$this->displayed[$i] = @$value ? true : false;
			$value && $none_displayed = false;
		}

		/*
		 * Redirecting when neccessary
		 * (hackity hack with unregistering/unchecking fields)
		 */

		if ($prepare_filter && ! $headers_sent) {
			$this->execute_redirect();
			exit;
		}

		/*
		 * Check if field selection report screen has to be displayed
		 */

		if (isset($fields_select) || $force_select || $none_displayed) {
			$this->execute_report_screen($table_cols);
			return true;
		}

		if (0) {
			$this->message .= $this->get_select_fields_link();
		}

		// parent class call
		return parent::execute();
	} /* }}} */

	function execute_redirect() /* {{{ */
	{
		global $HTTP_SERVER_VARS;
		global $HTTP_GET_VARS;
		global $HTTP_POST_VARS;
		$redirect_url = 'http://'.$HTTP_SERVER_VARS['HTTP_HOST'].$HTTP_SERVER_VARS['SCRIPT_NAME'];
		$delim = '?';
		foreach ($HTTP_POST_VARS + $HTTP_GET_VARS as $cgi_var_name => $cgi_var_value) {
			$cgi_var_name == 'prepare_filter' && $cgi_var_name = 'filter';
			$redirect_url .= $delim;
			$redirect_url .= rawurlencode($cgi_var_name).'='.rawurlencode($cgi_var_value);
			$delim == '?' && $delim = '&';
		}
		$redirect_url .= $this->cgi['persist'];
		header('Location: '.$redirect_url);
		exit;
	} /* }}} */

	function execute_report_screen($table_cols) /* {{{ */
	{
		echo '<form class="',$this->getCSSclass('form'),'" action="';
		echo htmlspecialchars($this->page_name),'" method="POST">',"\n";
		if ($this->nav_up()) {
			$this->display_report_selection_buttons('up');
			echo '<hr class="',$this->getCSSclass('hr', 'up'),'">',"\n";
		}
		echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";

		$i = 0;
		foreach ($table_cols as $key => $val) {
			$css_postfix    = @$this->fdd[$key]['css']['postfix'];
			$css_class_name = $this->getCSSclass('input', null, true, $css_postfix);
			$varname        = 'have_'.$key;
			$value          = $this->get_cgi_cookie_var($varname);
			$checked        = @$value ? ' checked' : ''; 
			echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n";
			echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">';
			echo $this->fdd[$i]['name'],'</td>',"\n";
			echo '<td class="',$this->getCSSclass('check', null, true, $css_postfix),'">';
			echo '<input class="',$css_class_name,'" type="checkbox" name="';
			echo htmlspecialchars($varname),'"',$checked,'>';
			echo '</td>',"\n";
			echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
			echo $this->getColAttributes($key),">\n";
			$varname = 'qf'.$i;
			$value   = $this->get_cgi_cookie_var($varname);
			if ($this->fdd[$key]['select'] == 'D' || $this->fdd[$key]['select'] == 'M') {
				$from_table = ! $this->col_has_values($key) || isset($this->fdd[$key]['values']['table']);
				$selected   = $value;
				$value      = $this->set_values($key, array('*' => '*'), null, $from_table);
				$multiple   = $this->col_has_multiple_select($key);
				$multiple  |= $this->fdd[$key]['select'] == 'M';
				$readonly   = false;
				$strip_tags = true;
				$escape     = true;
				echo $this->htmlSelect($varname.'_id', $css_class_name, $value, $selected,
						$multiple, $readonly, $strip_tags, $escape);
			} else {
				echo '<input class="',$css_class_name,'" type=text name="';
				echo htmlspecialchars($varname),'" value="',htmlspecialchars($value),'" size="';
				echo min(40, $val),'" maxlength="',min(40, max(10, $val)),'">';
			}
			echo '</td>',"\n",'</tr>',"\n";
			$i++;
		}
		echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n";
		echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'" colspan="2">';
		echo $this->labels['Records per screen'],'</td>';
		echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'">';
		echo '<input class="',$css_class_name,'" type="text" name="inc" value="',$this->inc.'">';
		echo '</td></tr>',"\n";
		echo '</table>',"\n";
		if ($this->nav_down()) {
			echo '<hr class="',$this->getCSSclass('hr', 'down'),'">',"\n";
			$this->display_report_selection_buttons('down');
		}
		echo '</form>';
	} /* }}} */

}

/* Modeline for ViM {{{
 * vim:set ts=4:
 * vim600:fdm=marker fdl=0 fdc=0:
 * }}} */

?>
Any help is much appreciated, I'm tearing my hair out trying to figure out what is wrong.

Thanks in advance!

Re: Broken mysql query in IE, works in other browsers

Posted: Thu May 06, 2010 11:41 am
by quakefiend420
At this point I think the problem lies in the redirect in the reports extension, however I have no idea how to fix it :(

Re: Broken mysql query in IE, works in other browsers

Posted: Thu May 06, 2010 2:50 pm
by pickle
I didn't look through your code - so this is just off the top of my head:

IE/Firefox/Opera/any other browser does not run the MySQL query - only the server does. The only way the browser can affect the query, is if the query uses information sent from the browser - through $_GET[] or $_POST[].
  1. Echo your query - see if it's what you expect it is. I'm guessing when you echo the query from IE, it's not going to be in the format you expect - some variables will be missing.
  2. Validate your HTML - It's possible the html is broken, and IE is the only browser that isn't interpreting it in the way you want.

Re: Broken mysql query in IE, works in other browsers

Posted: Fri May 07, 2010 12:03 pm
by quakefiend420
I've discovered something, sometimes a javascript function fails to load, what would cause this to load intermittently?

When it works this is the HTML output:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
		"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Chase Alarm Codes</title>
<style type="text/css"> 
	hr.pme-hr		     { border: 0px solid; padding: 0px; margin: 0px; border-top-width: 1px; height: 1px; }
	table.pme-main 	     { border: #004d9c 1px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; }
	table.pme-navigation { border: #004d9c 0px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; }
	td.pme-navigation-0, td.pme-navigation-1 { white-space: nowrap; }
	th.pme-header	     { border: #004d9c 1px solid; padding: 4px; background: #add8e6; }
	td.pme-key-0, td.pme-value-0, td.pme-help-0, td.pme-navigation-0, td.pme-cell-0,
	td.pme-key-1, td.pme-value-1, td.pme-help-0, td.pme-navigation-1, td.pme-cell-1,
	td.pme-sortinfo, td.pme-filter { border: #004d9c 1px solid; padding: 3px; }
	td.pme-buttons { text-align: left;   }
	td.pme-message { text-align: center; }
	td.pme-stats   { text-align: right;  }
</style>
</head>
<body>
<h3>Chase Alarm Codes</h3>
<script type="text/javascript"><!--
 
function PME_js_filter_handler(theForm, theEvent)
{
	var pressed_key = null;
	if (theEvent.which) {
		pressed_key = theEvent.which;
	} else {
		pressed_key = theEvent.keyCode;
	}
	if (pressed_key == 13) { // enter pressed
		theForm.submit();
		return false;
	}
	return true;
}
 
// --></script>
<form class="pme-form" method="post" action="alarm_codes.php" name="PME_sys_form">
When it fails:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
		"http://www.w3.org/TR/html4/loose.dtd">
<html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
		"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>My Page</title>
<style type="text/css"> 
	hr.pme-hr		     { border: 0px solid; padding: 0px; margin: 0px; border-top-width: 1px; height: 1px; }
	table.pme-main 	     { border: #004d9c 1px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; }
	table.pme-navigation { border: #004d9c 0px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; }
	td.pme-navigation-0, td.pme-navigation-1 { white-space: nowrap; }
	th.pme-header	     { border: #004d9c 1px solid; padding: 4px; background: #add8e6; }
	td.pme-key-0, td.pme-value-0, td.pme-help-0, td.pme-navigation-0, td.pme-cell-0,
	td.pme-key-1, td.pme-value-1, td.pme-help-0, td.pme-navigation-1, td.pme-cell-1,
	td.pme-sortinfo, td.pme-filter { border: #004d9c 1px solid; padding: 3px; }
	td.pme-buttons { text-align: left;   }
	td.pme-message { text-align: center; }
	td.pme-stats   { text-align: right;  }
</style>
</head>
<body>
<h3>My Page</h3>
<form class="pme-form" method="post" action="my_php.php" name="PME_sys_form">
JS completely missing.

Also, if i wait about 45 seconds between searches, it seems to work just fine...

I did run the HTML output through a validator and it passed. I've also tried echoing the $POST and $GET variables, but all i get is "array, array". forgive my n00bness :oops:

Re: Broken mysql query in IE, works in other browsers

Posted: Mon May 10, 2010 12:56 pm
by quakefiend420
I'm still lost here, I've tried googling for intermittent javascript loads in IE, but haven't really gotten anywhere...does anyone else have any suggestions for me?

Re: UPDATED:Javascript function call loading intermitently i

Posted: Mon May 10, 2010 3:50 pm
by pickle
How is that Javascript being put in the page? Do you have a PHP script that outputs the page content? I'd think that's the culprit.

As to what could be causing that - is there a condition in your PHP script that only outputs that Javascript if a condition is met? Maybe that condition isn't being met.

Re: UPDATED:Javascript function call loading intermitently i

Posted: Tue May 11, 2010 9:54 am
by quakefiend420
Yes, it's the PHP script that does it. Here's the code:

Code: Select all

	function form_begin() /* {{{ */
	{
		$page_name = htmlspecialchars($this->page_name);
		if ($this->add_operation() || $this->change_operation() || $this->copy_operation()
				|| $this->view_operation() || $this->delete_operation()) {
			$field_to_tab = array();
			for ($tab = $k = $this->cur_tab = 0; $k < $this->num_fds; $k++) {
				if (isset($this->fdd[$k]['tab'])) {
					if ($tab == 0 && $k > 0) {
						$this->tabs[0] = 'PMEtab0';
						$this->cur_tab = 1;
						$tab++;
					}
					if (is_array($this->fdd[$k]['tab'])) {
						$this->tabs[$tab] = @$this->fdd[$k]['tab']['name'];
						$this->fdd[$k]['tab']['default'] && $this->cur_tab = $tab;
					} else {
						$this->tabs[$tab] = @$this->fdd[$k]['tab'];
					}
					$tab++;
				}
				$field_to_tab[$k] = max(0, $tab - 1);
			}
			if (preg_match('/^'.$this->dhtml['prefix'].'tab(\d+)$/', $this->get_sys_cgi_var('cur_tab'), $parts)) {
				$this->cur_tab = $parts[1];
			}
			if ($this->tabs_enabled()) {
				// initial TAB styles
				echo '<style type="text/css" media="screen">',"\n";
				for ($i = 0; $i < count($this->tabs); $i++) {
					echo '	#'.$this->dhtml['prefix'].'tab',$i,' { display: ';
					echo (($i == $this->cur_tab || $this->tabs[$i] == 'PMEtab0' ) ? 'block' : 'none') ,'; }',"\n";
				}
				echo '</style>',"\n";
				// TAB javascripts
				echo '<script type="text/javascript"><!--',"\n\n";
				$css_class_name1 = $this->getCSSclass('tab', $position);
				$css_class_name2 = $this->getCSSclass('tab-selected', $position);
				echo 'var '.$this->js['prefix'].'cur_tab  = "'.$this->dhtml['prefix'].'tab',$this->cur_tab,'";

function '.$this->js['prefix'].'show_tab(tab_name)
{';
				if ($this->nav_up()) {
					echo '
	document.getElementById('.$this->js['prefix'].'cur_tab+"_up_label").className = "',$css_class_name1,'";
	document.getElementById('.$this->js['prefix'].'cur_tab+"_up_link").className = "',$css_class_name1,'";
	document.getElementById(tab_name+"_up_label").className = "',$css_class_name2,'";
	document.getElementById(tab_name+"_up_link").className = "',$css_class_name2,'";';
				}
				if ($this->nav_down()) {
					echo '
	document.getElementById('.$this->js['prefix'].'cur_tab+"_down_label").className = "',$css_class_name1,'";
	document.getElementById('.$this->js['prefix'].'cur_tab+"_down_link").className = "',$css_class_name1,'";
	document.getElementById(tab_name+"_down_label").className = "',$css_class_name2,'";
	document.getElementById(tab_name+"_down_link").className = "',$css_class_name2,'";';
				}
				echo '
	document.getElementById('.$this->js['prefix'].'cur_tab).style.display = "none";
	document.getElementById(tab_name).style.display = "block";
	'.$this->js['prefix'].'cur_tab = tab_name;
	document.'.$this->cgi['prefix']['sys'].'form.'.$this->cgi['prefix']['sys'].'cur_tab.value = tab_name;
}',"\n\n";
				echo '// --></script>', "\n";
			}
		}

		if ($this->add_operation() || $this->change_operation() || $this->copy_operation()) {
			$first_required = true;
			for ($k = 0; $k < $this->num_fds; $k++) {
				if ($this->displayed[$k] && ! $this->readonly($k) && ! $this->hidden($k)
						&& ($this->fdd[$k]['js']['required'] || isset($this->fdd[$k]['js']['regexp']))) {
					if ($first_required) {
				 		$first_required = false;
						echo '<script type="text/javascript"><!--',"\n";
						echo '
function '.$this->js['prefix'].'trim(str)
{
	while (str.substring(0, 1) == " "
			|| str.substring(0, 1) == "\\n"
			|| str.substring(0, 1) == "\\r")
	{
		str = str.substring(1, str.length);
	}
	while (str.substring(str.length - 1, str.length) == " "
			|| str.substring(str.length - 1, str.length) == "\\n"
			|| str.substring(str.length - 1, str.length) == "\\r")
	{
		str = str.substring(0, str.length - 1);
	}
	return str;
}

function '.$this->js['prefix'].'form_control(theForm)
{',"\n";
					}
					if ($this->col_has_values($k)) {
						$condition = 'theForm.'.$this->cgi['prefix']['data'].$this->fds[$k].'.selectedIndex == -1';
						$multiple  = $this->col_has_multiple_select($k);
					} else {
						$condition = '';
						$multiple  = false;
						if ($this->fdd[$k]['js']['required']) {
							$condition = $this->js['prefix'].'trim(theForm.'.$this->cgi['prefix']['data'].$this->fds[$k].'.value) == ""';
						}
						if (isset($this->fdd[$k]['js']['regexp'])) {
							$condition .= (strlen($condition) > 0 ? ' || ' : '');
							$condition .= sprintf('!(%s.test('.$this->js['prefix'].'trim(theForm.%s.value)))',
									$this->fdd[$k]['js']['regexp'], $this->cgi['prefix']['data'].$this->fds[$k]);
						}
					}

					/* Multiple selects have their name like ''name[]''.
					   It is not possible to work with them directly, because
					   theForm.name[].something will result into JavaScript
					   syntax error. Following search algorithm is provided
					   as a workaround for this.
					 */
					if ($multiple) {
						echo '
	multiple_select = null;
	for (i = 0; i < theForm.length; i++) {
		if (theForm.elements[i].name == "',$this->cgi['prefix']['data'].$this->fds[$k],'[]") {
			multiple_select = theForm.elements[i];
			break;
		}
	}
	if (multiple_select != null && multiple_select.selectedIndex == -1) {';
					} else {
						echo '
	if (',$condition,') {';
					}
					echo '
		alert("';
					if (isset($this->fdd[$k]['js']['hint'])) {
						echo htmlspecialchars($this->fdd[$k]['js']['hint']);
					} else {
						echo $this->labels['Please enter'],' ',$this->fdd[$k]['name'],'.';
					}
					echo '");';
					if ($this->tabs_enabled() && $field_to_tab[$k] >= $this->cur_tab) {
						echo '
		'.$this->js['prefix'].'show_tab("'.$this->dhtml['prefix'].'tab',$field_to_tab[$k],'");';
					}
					echo '
		theForm.',$this->cgi['prefix']['data'].$this->fds[$k],'.focus();
		return false;
	}',"\n";
				}
			}
			if (! $first_required) {
				echo '
	return true;
}',"\n\n";
				echo '// --></script>', "\n";
			}
		}

		if ($this->filter_operation()) {
				echo '<script type="text/javascript"><!--',"\n";
				echo '
function '.$this->js['prefix'].'filter_handler(theForm, theEvent)
{
	var pressed_key = null;
	if (theEvent.which) {
		pressed_key = theEvent.which;
	} else {
		pressed_key = theEvent.keyCode;
	}
	if (pressed_key == 13) { // enter pressed
		theForm.submit();
		return false;
	}
	return true;
}',"\n\n";
				echo '// --></script>', "\n";
		}

		if ($this->display['form']) {
			echo '<form class="',$this->getCSSclass('form'),'" method="post"';
			echo ' action="',$page_name,'" name="'.$this->cgi['prefix']['sys'].'form">',"\n";
		}
		return true;
	} /* }}} */

	function form_end() /* {{{ */
	{
		if ($this->display['form']) {
			echo '</form>',"\n";
		}
	} /* }}} */
The only condition i see is:

if ($this->display['form']) {
echo '</form>',"\n";

However I'm quite new to all of this still, so it may not be what I think it is.

Re: UPDATED:Javascript function call loading intermitently i

Posted: Tue May 11, 2010 9:58 am
by pickle
It looks like the condition

Code: Select all

if ($this->filter_operation())
is failing.

Re: UPDATED:Javascript function call loading intermitently i

Posted: Tue May 11, 2010 10:29 am
by quakefiend420
pickle wrote:It looks like the condition

Code: Select all

if ($this->filter_operation())
is failing.
Removing it doesn't seem to make a difference.

Code: Select all

echo '// --></script>', "\n";
			}
		}

		{
				echo '<script type="text/javascript"><!--',"\n";
				echo '
function '.$this->js['prefix'].'filter_handler(theForm, theEvent)
That should have it echo the script each time regardless of whether it's a filter operation or not, correct?

I didn't get any errors, but it still behaves the same way.