Index: trunk/wb/modules/form/modify_settings.php
===================================================================
--- trunk/wb/modules/form/modify_settings.php	(revision 297)
+++ trunk/wb/modules/form/modify_settings.php	(revision 298)
@@ -1,7 +1,7 @@
 <?php
 
 // $Id$
-
+
 /*
 
  Website Baker Project <http://www.websitebaker.org/>
@@ -27,66 +27,66 @@
 The Website Baker Project would like to thank Rudolph Lartey <www.carbonect.com>
 for his contributions to this module - adding extra field types
 */
-
-require('../../config.php');
-
-// Include WB admin wrapper script
-require(WB_PATH.'/modules/admin.php');
-
-// Get header and footer
-$query_content = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
-$setting = $query_content->fetchRow();
-
-// Set raw html <'s and >'s to be replace by friendly html code
-$raw = array('<', '>');
-$friendly = array('&lt;', '&gt;');
-
-?>
-
-<style type="text/css">
-.setting_name {
-	vertical-align: top;
-}
-</style>
-
-<form name="edit" action="<?php echo WB_URL; ?>/modules/form/save_settings.php" method="post" style="margin: 0;">
-
-<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
-<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
-
-<table cellpadding="2" cellspacing="0" border="0" width="100%">
-<tr>
-	<td class="setting_name" width="220"><?php echo $TEXT['HEADER']; ?>:</td>
-	<td class="setting_name">
-		<textarea name="header" style="width: 100%; height: 80px;"><?php echo ($setting['header']); ?></textarea>
-	</td>
-</tr>
-<tr>
-	<td class="setting_name"><?php echo $TEXT['FIELD'].' '.$TEXT['LOOP']; ?>:</td>
-	<td class="setting_name">
-		<textarea name="field_loop" style="width: 100%; height: 60px;"><?php echo ($setting['field_loop']); ?></textarea>
-	</td>
-</tr>
-<tr>
-	<td class="setting_name"><?php echo $TEXT['FOOTER']; ?>:</td>
-	<td class="setting_name">
-		<textarea name="footer" style="width: 100%; height: 80px;"><?php echo str_replace($raw, $friendly, ($setting['footer'])); ?></textarea>
-	</td>
-</tr>
-<tr>
-	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['TO']; ?>:</td>
-	<td class="setting_name">
-		<textarea name="email_to" style="width: 100%; height: 30px;"><?php echo str_replace($raw, $friendly, ($setting['email_to'])); ?></textarea>
-	</td>
-</tr>
-<tr>
-	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['FROM']; ?>:</td>
+
+require('../../config.php');
+
+// Include WB admin wrapper script
+require(WB_PATH.'/modules/admin.php');
+
+// Get header and footer
+$query_content = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
+$setting = $query_content->fetchRow();
+
+// Set raw html <'s and >'s to be replace by friendly html code
+$raw = array('<', '>');
+$friendly = array('&lt;', '&gt;');
+
+?>
+
+<style type="text/css">
+.setting_name {
+	vertical-align: top;
+}
+</style>
+
+<form name="edit" action="<?php echo WB_URL; ?>/modules/form/save_settings.php" method="post" style="margin: 0;">
+
+<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
+<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
+
+<table cellpadding="2" cellspacing="0" border="0" width="100%">
+<tr>
+	<td class="setting_name" width="220"><?php echo $TEXT['HEADER']; ?>:</td>
 	<td class="setting_name">
+		<textarea name="header" style="width: 100%; height: 80px;"><?php echo ($setting['header']); ?></textarea>
+	</td>
+</tr>
+<tr>
+	<td class="setting_name"><?php echo $TEXT['FIELD'].' '.$TEXT['LOOP']; ?>:</td>
+	<td class="setting_name">
+		<textarea name="field_loop" style="width: 100%; height: 60px;"><?php echo ($setting['field_loop']); ?></textarea>
+	</td>
+</tr>
+<tr>
+	<td class="setting_name"><?php echo $TEXT['FOOTER']; ?>:</td>
+	<td class="setting_name">
+		<textarea name="footer" style="width: 100%; height: 80px;"><?php echo str_replace($raw, $friendly, ($setting['footer'])); ?></textarea>
+	</td>
+</tr>
+<tr>
+	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['TO']; ?>:</td>
+	<td class="setting_name">
+		<textarea name="email_to" style="width: 100%; height: 30px;"><?php echo str_replace($raw, $friendly, ($setting['email_to'])); ?></textarea>
+	</td>
+</tr>
+<tr>
+	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['FROM']; ?>:</td>
+	<td class="setting_name">
 		<select name="email_from_field" style="width: 100%;">
 			<option value="" onclick="javascript: document.getElementById('email_from').style.display = 'block';"><?php echo $TEXT['CUSTOM']; ?>:</option>
 			<?php
 			$email_from_value = str_replace($raw, $friendly, ($setting['email_from']));
-			$query_email_fields = $database->query("SELECT field_id,title FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
+			$query_email_fields = $database->query("SELECT field_id,title FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' AND ( type = 'textfield' OR  type = 'email' ) ORDER BY position ASC");
 			if($query_email_fields->numRows() > 0) {
 				while($field = $query_email_fields->fetchRow()) {
 					?>
@@ -97,34 +97,34 @@
 				}
 			}
 			?>
-		</select>
-		<input type="text" name="email_from" id="email_from" style="width: 100%; display: <?php if(isset($selected) AND $selected == true) { echo 'none'; } else { echo 'block'; } ?>;" maxlength="255" value="<?php if(substr($email_from_value, 0, 5) != 'field') { echo $email_from_value; } ?>" />
-	</td>
-</tr>
-<tr>
-	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['SUBJECT']; ?>:</td>
-	<td class="setting_name">
-		<input type="text" name="email_subject" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['email_subject'])); ?>" />
-	</td>
-</tr>
-<tr>
-	<td class="setting_name"><?php echo $TEXT['SUCCESS'].' '.$TEXT['MESSAGE']; ?>:</td>
-	<td class="setting_name">
-		<textarea name="success_message" style="width: 100%; height: 80px;"><?php echo str_replace($raw, $friendly, ($setting['success_message'])); ?></textarea>
-	</td>
+		</select>
+		<input type="text" name="email_from" id="email_from" style="width: 100%; display: <?php if(isset($selected) AND $selected == true) { echo 'none'; } else { echo 'block'; } ?>;" maxlength="255" value="<?php if(substr($email_from_value, 0, 5) != 'field') { echo $email_from_value; } ?>" />
+	</td>
 </tr>
-<tr>
-	<td class="setting_name"><?php echo $TEXT['MAX_SUBMISSIONS_PER_HOUR']; ?>:</td>
-	<td class="setting_name">
-		<input type="text" name="max_submissions" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['max_submissions'])); ?>" />
-	</td>
+<tr>
+	<td class="setting_name"><?php echo $TEXT['EMAIL'].' '.$TEXT['SUBJECT']; ?>:</td>
+	<td class="setting_name">
+		<input type="text" name="email_subject" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['email_subject'])); ?>" />
+	</td>
 </tr>
-<tr>
-	<td class="setting_name"><?php echo $TEXT['SUBMISSIONS_STORED_IN_DATABASE']; ?>:</td>
-	<td class="setting_name">
-		<input type="text" name="stored_submissions" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['stored_submissions'])); ?>" />
-	</td>
+<tr>
+	<td class="setting_name"><?php echo $TEXT['SUCCESS'].' '.$TEXT['MESSAGE']; ?>:</td>
+	<td class="setting_name">
+		<textarea name="success_message" style="width: 100%; height: 80px;"><?php echo str_replace($raw, $friendly, ($setting['success_message'])); ?></textarea>
+	</td>
 </tr>
+<tr>
+	<td class="setting_name"><?php echo $TEXT['MAX_SUBMISSIONS_PER_HOUR']; ?>:</td>
+	<td class="setting_name">
+		<input type="text" name="max_submissions" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['max_submissions'])); ?>" />
+	</td>
+</tr>
+<tr>
+	<td class="setting_name"><?php echo $TEXT['SUBMISSIONS_STORED_IN_DATABASE']; ?>:</td>
+	<td class="setting_name">
+		<input type="text" name="stored_submissions" style="width: 100%;" maxlength="255" value="<?php echo str_replace($raw, $friendly, ($setting['stored_submissions'])); ?>" />
+	</td>
+</tr>
 <?php if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) { /* Make's sure GD library is installed */ ?>
 <tr>
 	<td class="setting_name"><?php echo $TEXT['CAPTCHA_VERIFICATION']; ?>:</td>
@@ -135,24 +135,24 @@
 		<label for="use_captcha_false"><?php echo $TEXT['DISABLED']; ?></label>
 	</td>
 </tr>
-<?php } ?>
-</table>
-<table cellpadding="0" cellspacing="0" border="0" width="100%">
-<tr>
-	<td width="225">&nbsp;</td>
-	<td align="left">
-		<input name="save" type="submit" value="<?php echo $TEXT['SAVE'].' '.$TEXT['SETTINGS']; ?>" style="width: 200px; margin-top: 5px;"></form>
-	</td>
-	<td align="right">
-		<input type="button" value="<?php echo $TEXT['CANCEL']; ?>" onclick="javascript: window.location = '<?php echo ADMIN_URL; ?>/pages/modify.php?page_id=<?php echo $page_id; ?>';" style="width: 100px; margin-top: 5px;" />
-	</td>
-</tr>
-</table>
-
-
-<?php
-
-// Print admin footer
-$admin->print_footer();
-
+<?php } ?>
+</table>
+<table cellpadding="0" cellspacing="0" border="0" width="100%">
+<tr>
+	<td width="225">&nbsp;</td>
+	<td align="left">
+		<input name="save" type="submit" value="<?php echo $TEXT['SAVE'].' '.$TEXT['SETTINGS']; ?>" style="width: 200px; margin-top: 5px;"></form>
+	</td>
+	<td align="right">
+		<input type="button" value="<?php echo $TEXT['CANCEL']; ?>" onclick="javascript: window.location = '<?php echo ADMIN_URL; ?>/pages/modify.php?page_id=<?php echo $page_id; ?>';" style="width: 100px; margin-top: 5px;" />
+	</td>
+</tr>
+</table>
+
+
+<?php
+
+// Print admin footer
+$admin->print_footer();
+
 ?>
\ No newline at end of file
Index: trunk/wb/modules/form/view.php
===================================================================
--- trunk/wb/modules/form/view.php	(revision 297)
+++ trunk/wb/modules/form/view.php	(revision 298)
@@ -27,162 +27,162 @@
 The Website Baker Project would like to thank Rudolph Lartey <www.carbonect.com>
 for his contributions to this module - adding extra field types
 */
-
-// Must include code to stop this file being access directly
+
+// Must include code to stop this file being access directly
 if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
-
+
 // Function for generating an optionsfor a select field
-function make_option(&$n) {
-	// start option group if it exists
-	if (substr($n,0,2) == '[=') {
-	 	$n = '<optgroup label="'.substr($n,2,strlen($n)).'">';
-	} elseif ($n == ']') {
-		$n = '</optgroup>';
-	} else {
-		$n = '<option value="'.$n.'">'.$n.'</option>';
-	}
-}
-
+function make_option(&$n) {
+	// start option group if it exists
+	if (substr($n,0,2) == '[=') {
+	 	$n = '<optgroup label="'.substr($n,2,strlen($n)).'">';
+	} elseif ($n == ']') {
+		$n = '</optgroup>';
+	} else {
+		$n = '<option value="'.$n.'">'.$n.'</option>';
+	}
+}
+
 // Function for generating a checkbox
-function make_checkbox(&$n, $idx, $params) {
-	$field_id = $params[0];
-	$seperator = $params[1];
-	//$n = '<input class="field_checkbox" type="checkbox" id="'.$n.'" name="field'.$field_id.'" value="'.$n.'">'.'<font class="checkbox_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = !document.getElementById(\''.$n.'\').checked;">'.$n.'</font>'.$seperator;
-	$n = '<input class="field_checkbox" type="checkbox" id="'.$n.'" name="field'.$field_id.'['.$idx.']" value="'.$n.'">'.'<font class="checkbox_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = !document.getElementById(\''.$n.'\').checked;">'.$n.'</font>'.$seperator;
-}
-
+function make_checkbox(&$n, $idx, $params) {
+	$field_id = $params[0];
+	$seperator = $params[1];
+	//$n = '<input class="field_checkbox" type="checkbox" id="'.$n.'" name="field'.$field_id.'" value="'.$n.'">'.'<font class="checkbox_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = !document.getElementById(\''.$n.'\').checked;">'.$n.'</font>'.$seperator;
+	$n = '<input class="field_checkbox" type="checkbox" id="'.$n.'" name="field'.$field_id.'['.$idx.']" value="'.$n.'">'.'<font class="checkbox_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = !document.getElementById(\''.$n.'\').checked;">'.$n.'</font>'.$seperator;
+}
+
 // Function for generating a radio button
-function make_radio(&$n, $idx, $params) {
-	$field_id = $params[0];
-	$group = $params[1];
-	$seperator = $params[2];
-	$n = '<input class="field_radio" type="radio" id="'.$n.'" name="field'.$field_id.'" value="'.$n.'">'.'<font class="radio_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = true;">'.$n.'</font>'.$seperator;
+function make_radio(&$n, $idx, $params) {
+	$field_id = $params[0];
+	$group = $params[1];
+	$seperator = $params[2];
+	$n = '<input class="field_radio" type="radio" id="'.$n.'" name="field'.$field_id.'" value="'.$n.'">'.'<font class="radio_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = true;">'.$n.'</font>'.$seperator;
 }
-
-// Work-out if the form has been submitted or not
-if($_POST == array()) {
-
-?>
-<style type="text/css">
-.required {
-	color: #FF0000;
-}
-.field_title {
-	font-size: 12px;
-	width: 100px;
-	vertical-align: top;
-	text-align:right;
-}
-.textfield {
-	font-size: 12px;
-	width: 200px;
-}
-.textarea {
-	font-size: 12px;
-	width: 90%;
-	height: 100px;
-}
-.field_heading {
-	font-size: 12px;
-	font-weight: bold;
-	border-bottom-width: 2px;
-	border-bottom-style: solid;
-	border-bottom-color: #666666;
-	padding-top: 10px;
-	color: #666666;
-}
-.select {
-	font-size: 12px;
-}
-.checkbox_label {
+
+// Work-out if the form has been submitted or not
+if($_POST == array()) {
+
+?>
+<style type="text/css">
+.required {
+	color: #FF0000;
+}
+.field_title {
+	font-size: 12px;
+	width: 100px;
+	vertical-align: top;
+	text-align:right;
+}
+.textfield {
+	font-size: 12px;
+	width: 200px;
+}
+.textarea {
+	font-size: 12px;
+	width: 90%;
+	height: 100px;
+}
+.field_heading {
+	font-size: 12px;
+	font-weight: bold;
+	border-bottom-width: 2px;
+	border-bottom-style: solid;
+	border-bottom-color: #666666;
+	padding-top: 10px;
+	color: #666666;
+}
+.select {
+	font-size: 12px;
+}
+.checkbox_label {
 	font-size: 11px;
-	cursor: pointer;
-}
-.radio_label {
+	cursor: pointer;
+}
+.radio_label {
 	font-size: 11px;
-	cursor: pointer;
+	cursor: pointer;
 }
-.email {
-	font-size: 12px;
-	width: 200px;
-}
-</style>
-<?php
-
-// Get settings
-$query_settings = $database->query("SELECT header,field_loop,footer,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
-if($query_settings->numRows() > 0) {
-	$fetch_settings = $query_settings->fetchRow();
-	$header = str_replace('{WB_URL}',WB_URL,$fetch_settings['header']);
-	$field_loop = $fetch_settings['field_loop'];
+.email {
+	font-size: 12px;
+	width: 200px;
+}
+</style>
+<?php
+
+// Get settings
+$query_settings = $database->query("SELECT header,field_loop,footer,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
+if($query_settings->numRows() > 0) {
+	$fetch_settings = $query_settings->fetchRow();
+	$header = str_replace('{WB_URL}',WB_URL,$fetch_settings['header']);
+	$field_loop = $fetch_settings['field_loop'];
 	$footer = str_replace('{WB_URL}',WB_URL,$fetch_settings['footer']);
-	$use_captcha = $fetch_settings['use_captcha'];
-} else {
-	$header = '';
-	$field_loop = '';
-	$footer = '';
-}
-
-// Add form starter code
-?>
-<form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
-<?php
-
-// Print header
-echo $header;
-
-// Get list of fields
-$query_fields = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
-if($query_fields->numRows() > 0) {
-	while($field = $query_fields->fetchRow()) {
-		// Set field values
-		$field_id = $field['field_id'];
-		$value = $field['value'];
-		// Print field_loop after replacing vars with values
-		$vars = array('{TITLE}', '{REQUIRED}');
-		$values = array($field['title']);
-		if($field['required'] == 1) {
-			$values[] = '<font class="required">*</font>';
-		} else {
-			$values[] = '';
-		}
-		if($field['type'] == 'textfield') {
-			$vars[] = '{FIELD}';
-			$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" maxlength="'.$field['extra'].'" value="'.$value.'" class="textfield" />';
-		} elseif($field['type'] == 'textarea') {
-			$vars[] = '{FIELD}';
-			$values[] = '<textarea name="field'.$field_id.'" id="field'.$field_id.'" class="textarea">'.$value.'</textarea>';
-		} elseif($field['type'] == 'select') {
-			$vars[] = '{FIELD}';
-			$options = explode(',', $value);
-			array_walk($options, 'make_option');
-			$field['extra'] = explode(',',$field['extra']); 
-			$values[] = '<select name="field'.$field_id.'[]" id="field'.$field_id.'" size="'.$field['extra'][0].'" '.$field['extra'][1].' class="select">'.implode($options).'</select>';
-		} elseif($field['type'] == 'heading') {
-			$vars[] = '{FIELD}';
-			$values[] = '<input type="hidden" name="field'.$field_id.'" id="field'.$field_id.'" value="===['.$field['title'].']===" />';
-			$tmp_field_loop = $field_loop;		// temporarily modify the field loop template
-			$field_loop = $field['extra'];
-		} elseif($field['type'] == 'checkbox') {
-			$vars[] = '{FIELD}';
-			$options = explode(',', $value);
-			array_walk($options, 'make_checkbox',array($field_id,$field['extra']));
-			$values[] = implode($options);
-		} elseif($field['type'] == 'radio') {
-			$vars[] = '{FIELD}';
-			$options = explode(',', $value);
-			array_walk($options, 'make_radio',array($field_id,$field['title'],$field['extra']));
-			$values[] = implode($options);
-		} elseif($field['type'] == 'email') {
-			$vars[] = '{FIELD}';
-			$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" maxlength="'.$field['extra'].'" class="email" />';
+	$use_captcha = $fetch_settings['use_captcha'];
+} else {
+	$header = '';
+	$field_loop = '';
+	$footer = '';
+}
+
+// Add form starter code
+?>
+<form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
+<?php
+
+// Print header
+echo $header;
+
+// Get list of fields
+$query_fields = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
+if($query_fields->numRows() > 0) {
+	while($field = $query_fields->fetchRow()) {
+		// Set field values
+		$field_id = $field['field_id'];
+		$value = $field['value'];
+		// Print field_loop after replacing vars with values
+		$vars = array('{TITLE}', '{REQUIRED}');
+		$values = array($field['title']);
+		if($field['required'] == 1) {
+			$values[] = '<font class="required">*</font>';
+		} else {
+			$values[] = '';
 		}
-		if($field['type'] != '') {
+		if($field['type'] == 'textfield') {
+			$vars[] = '{FIELD}';
+			$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" maxlength="'.$field['extra'].'" value="'.$value.'" class="textfield" />';
+		} elseif($field['type'] == 'textarea') {
+			$vars[] = '{FIELD}';
+			$values[] = '<textarea name="field'.$field_id.'" id="field'.$field_id.'" class="textarea">'.$value.'</textarea>';
+		} elseif($field['type'] == 'select') {
+			$vars[] = '{FIELD}';
+			$options = explode(',', $value);
+			array_walk($options, 'make_option');
+			$field['extra'] = explode(',',$field['extra']); 
+			$values[] = '<select name="field'.$field_id.'[]" id="field'.$field_id.'" size="'.$field['extra'][0].'" '.$field['extra'][1].' class="select">'.implode($options).'</select>';
+		} elseif($field['type'] == 'heading') {
+			$vars[] = '{FIELD}';
+			$values[] = '<input type="hidden" name="field'.$field_id.'" id="field'.$field_id.'" value="===['.$field['title'].']===" />';
+			$tmp_field_loop = $field_loop;		// temporarily modify the field loop template
+			$field_loop = $field['extra'];
+		} elseif($field['type'] == 'checkbox') {
+			$vars[] = '{FIELD}';
+			$options = explode(',', $value);
+			array_walk($options, 'make_checkbox',array($field_id,$field['extra']));
+			$values[] = implode($options);
+		} elseif($field['type'] == 'radio') {
+			$vars[] = '{FIELD}';
+			$options = explode(',', $value);
+			array_walk($options, 'make_radio',array($field_id,$field['title'],$field['extra']));
+			$values[] = implode($options);
+		} elseif($field['type'] == 'email') {
+			$vars[] = '{FIELD}';
+			$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" maxlength="'.$field['extra'].'" class="email" />';
+		}
+		if($field['type'] != '') {
 			echo str_replace($vars, $values, $field_loop);
-		}
-		if (isset($tmp_field_loop)) $field_loop = $tmp_field_loop;
-	}
-}
+		}
+		if (isset($tmp_field_loop)) $field_loop = $tmp_field_loop;
+	}
+}
 
 // Captcha
 if($use_captcha) {
@@ -192,75 +192,75 @@
 	}
 	?><tr><td class="field_title"><?php echo $TEXT['VERIFICATION']; ?>:</td><td>
 	<table cellpadding="2" cellspacing="0" border="0">
-	<tr><td><img src="<?php echo WB_URL; ?>/include/captcha.php" alt="Captcha" /></td>
+	<tr><td><img src="<?php echo WB_URL; ?>/include/captcha.php?t=<?php echo time(); ?>" alt="Captcha" /></td>
 	<td><input type="text" name="captcha" maxlength="5" /></td>
 	</tr></table>
 	</td></tr>
 	<?php
 }
-
-// Print footer
-echo $footer;
-
-// Add form end code
-?>
-</form>
-<?php
-
-} else {
-	
-	// Submit form data
-	// First start message settings
-	$query_settings = $database->query("SELECT email_to,email_from,email_subject,success_message,max_submissions,stored_submissions,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
-	if($query_settings->numRows() > 0) {
-		$fetch_settings = $query_settings->fetchRow();
-		$email_to = $fetch_settings['email_to'];
+
+// Print footer
+echo $footer;
+
+// Add form end code
+?>
+</form>
+<?php
+
+} else {
+	
+	// Submit form data
+	// First start message settings
+	$query_settings = $database->query("SELECT email_to,email_from,email_subject,success_message,max_submissions,stored_submissions,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
+	if($query_settings->numRows() > 0) {
+		$fetch_settings = $query_settings->fetchRow();
+		$email_to = $fetch_settings['email_to'];
 		$email_from = $fetch_settings['email_from'];
 		if(substr($email_from, 0, 5) == 'field') {
 			// Set the email from field to what the user entered in the specified field
 			$email_from = $wb->add_slashes($_POST[$email_from]);
-		}
-		$email_subject = $fetch_settings['email_subject'];
+		}
+		$email_subject = $fetch_settings['email_subject'];
 		$success_message = $fetch_settings['success_message'];
 		$max_submissions = $fetch_settings['max_submissions'];
 		$stored_submissions = $fetch_settings['stored_submissions'];
-		$use_captcha = $fetch_settings['use_captcha'];
-	} else {
-		exit($TEXT['UNDER_CONSTRUCTION']);
-	}
-	$email_body = '';
-	
-	// Create blank "required" array
-	$required = array();
-	
-	// Loop through fields and add to message body
-	// Get list of fields
-	$query_fields = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
-	if($query_fields->numRows() > 0) {
-		while($field = $query_fields->fetchRow()) {
+		$use_captcha = $fetch_settings['use_captcha'];
+	} else {
+		exit($TEXT['UNDER_CONSTRUCTION']);
+	}
+	$email_body = '';
+	
+	// Create blank "required" array
+	$required = array();
+	
+	// Loop through fields and add to message body
+	// Get list of fields
+	$query_fields = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
+	if($query_fields->numRows() > 0) {
+		while($field = $query_fields->fetchRow()) {
 			// Add to message body
-			if($field['type'] != '') {
+			if($field['type'] != '') {
 				if(!empty($_POST['field'.$field['field_id']])) {
 					if($field['type'] == 'email' AND $admin->validate_email($_POST['field'.$field['field_id']]) == false) {
 						$email_error = $MESSAGE['USERS']['INVALID_EMAIL'];
-					}
-					if($field['type'] == 'heading') {
-						$email_body .= $_POST['field'.$field['field_id']]."\n\n";
-					} elseif (!is_array($_POST['field'.$field['field_id']])) {
-						$email_body .= $field['title'].': '.$_POST['field'.$field['field_id']]."\n\n";
-					} else {
-						$email_body .= $field['title'].": \n";
-						foreach ($_POST['field'.$field['field_id']] as $k=>$v) {
-							$email_body .= $v."\n";
+					}
+					if($field['type'] == 'heading') {
+						$email_body .= $_POST['field'.$field['field_id']]."\n\n";
+					} elseif (!is_array($_POST['field'.$field['field_id']])) {
+						$email_body .= $field['title'].': '.$_POST['field'.$field['field_id']]."\n\n";
+					} else {
+						$email_body .= $field['title'].": \n";
+						foreach ($_POST['field'.$field['field_id']] as $k=>$v) {
+							$email_body .= $v."\n";
 						}
-						$email_body .= "\n";
+						$email_body .= "\n";
 					}
-				} elseif($field['required'] == 1) {
+				} elseif($field['required'] == 1) {
 					$required[] = $field['title'];
-				}
-			}
-		}
-	}
+				}
+			}
+		}
+	}
 	
 	// Captcha
 	if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) { /* Make's sure GD library is installed */
@@ -279,24 +279,24 @@
 	
 	// Addslashes to email body - proposed by Icheb in topic=1170.0
 	// $email_body = $wb->add_slashes($email_body);
-	
-	// Check if the user forgot to enter values into all the required fields
-	if($required != array()) {
+	
+	// Check if the user forgot to enter values into all the required fields
+	if($required != array()) {
 		if(!isset($MESSAGE['MOD_FORM']['REQUIRED_FIELDS'])) {
 			echo 'You must enter details for the following fields';
 		} else {
 			echo $MESSAGE['MOD_FORM']['REQUIRED_FIELDS'];
-		}
-		echo ':<br /><ul>';
-		foreach($required AS $field_title) {
-			echo '<li>'.$field_title;
 		}
+		echo ':<br /><ul>';
+		foreach($required AS $field_title) {
+			echo '<li>'.$field_title;
+		}
 		if(isset($email_error)) { echo '<li>'.$email_error.'</li>'; }
-		if(isset($captcha_error)) { echo '<li>'.$captcha_error.'</li>'; }
-		echo '</ul><a href="javascript: history.go(-1);">'.$TEXT['BACK'].'</a>';
-		
-	} else {
+		if(isset($captcha_error)) { echo '<li>'.$captcha_error.'</li>'; }
+		echo '</ul><a href="javascript: history.go(-1);">'.$TEXT['BACK'].'</a>';
 		
+	} else {
+		
 		if(isset($email_error)) {
 			echo '<br /><ul>';
 			echo '<li>'.$email_error.'</li>';
@@ -308,18 +308,17 @@
 		} else {
 		
 		// Check how many times form has been submitted in last hour
-		$query_submissions = $database->query("SELECT submission_id FROM ".TABLE_PREFIX."mod_form_submissions WHERE submitted_when >= '3600'");
+		$last_hour = time()-3600;
+		$query_submissions = $database->query("SELECT submission_id FROM ".TABLE_PREFIX."mod_form_submissions WHERE submitted_when >= '$last_hour'");
 		if($query_submissions->numRows() > $max_submissions) {
 			// Too many submissions so far this hour
 			echo $MESSAGE['MOD_FORM']['EXCESS_SUBMISSIONS'];
 			$success = false;
-		} else {
+		} else {
 			// Now send the email
-			if($email_to != '') {
-				if($email_from != '') {
-					if(mail($email_to,$email_subject,str_replace("\n", '', $email_body),"From: ".$email_from)) { $success = true; }
-				} else {
-					if(mail($email_to,$email_subject,str_replace("\n", '', $email_body))) { $success = true; }
+			if($email_to != '') {
+				if($email_from != '') {
+					if($wb->wb_mail($email_from,$email_to,$email_subject,$email_body)) { $success = true; }
 				}
 			}				
 			// Write submission to database
@@ -327,7 +326,7 @@
 				$admin->get_user_id();
 			} else {
 				$submitted_by = 0;
-			}
+			}
 			$email_body = $wb->add_slashes($email_body);
 			$database->query("INSERT INTO ".TABLE_PREFIX."mod_form_submissions (page_id,section_id,submitted_when,submitted_by,body) VALUES ('".PAGE_ID."','$section_id','".mktime()."','$submitted_by','$email_body')");
 			// Make sure submissions table isn't too full
@@ -348,17 +347,17 @@
 				$success = true;
 			}
 		}
-		
-		// Now check if the email was sent successfully
-		if(isset($success) AND $success == true) {
-			echo $success_message;
-		} else {
-			echo $TEXT['ERROR'];
+		
+		// Now check if the email was sent successfully
+		if(isset($success) AND $success == true) {
+			echo $success_message;
+		} else {
+			echo $TEXT['ERROR'];
 		}
-		
-		}
-	}
-	
+		
+		}
+	}
+	
 }
-
+
 ?>
\ No newline at end of file
Index: trunk/wb/modules/form/save_settings.php
===================================================================
--- trunk/wb/modules/form/save_settings.php	(revision 297)
+++ trunk/wb/modules/form/save_settings.php	(revision 298)
@@ -1,7 +1,7 @@
 <?php
 
 // $Id$
-
+
 /*
 
  Website Baker Project <http://www.websitebaker.org/>
@@ -27,19 +27,19 @@
 The Website Baker Project would like to thank Rudolph Lartey <www.carbonect.com>
 for his contributions to this module - adding extra field types
 */
-
-require('../../config.php');
-
-// Include WB admin wrapper script
-$update_when_modified = true; // Tells script to update when this page was last updated
-require(WB_PATH.'/modules/admin.php');
-
-// This code removes any <?php tags and adds slashes
-$friendly = array('&lt;', '&gt;', '?php');
-$raw = array('<', '>', '');
-$header = $admin->add_slashes($_POST['header']);
-$field_loop = $admin->add_slashes($_POST['field_loop']);
-$footer = $admin->add_slashes($_POST['footer']);
+
+require('../../config.php');
+
+// Include WB admin wrapper script
+$update_when_modified = true; // Tells script to update when this page was last updated
+require(WB_PATH.'/modules/admin.php');
+
+// This code removes any <?php tags and adds slashes
+$friendly = array('&lt;', '&gt;', '?php');
+$raw = array('<', '>', '');
+$header = $admin->add_slashes($_POST['header']);
+$field_loop = $admin->add_slashes($_POST['field_loop']);
+$footer = $admin->add_slashes($_POST['footer']);
 $email_to = $admin->add_slashes($_POST['email_to']);
 if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) {
 	$use_captcha = $_POST['use_captcha'];
@@ -46,12 +46,12 @@
 } else {
 	$use_captcha = false;
 }
-if($_POST['email_from_field'] == '') {
+if($_POST['email_from_field'] == '') {
 	$email_from = $admin->add_slashes($_POST['email_from']);
 } else {
 	$email_from = $admin->add_slashes($_POST['email_from_field']);
-}
-$email_subject = $admin->add_slashes($_POST['email_subject']);
+}
+$email_subject = $admin->add_slashes($_POST['email_subject']);
 $success_message = $admin->add_slashes($_POST['success_message']);
 if(!is_numeric($_POST['max_submissions'])) {
 	$max_submissions = 50;
@@ -63,22 +63,22 @@
 } else {
 	$stored_submissions = $_POST['stored_submissions'];
 }
-// Make sure max submissions is not smaller than stored submissions
-if($max_submissions < $stored_submissions) {
+// Make sure max submissions is not greater than stored submissions
+if($max_submissions > $stored_submissions) {
 	$max_submissions = $stored_submissions;
 }
-
-// Update settings
-$database->query("UPDATE ".TABLE_PREFIX."mod_form_settings SET header = '$header', field_loop = '$field_loop', footer = '$footer', email_to = '$email_to', email_from = '$email_from', email_subject = '$email_subject', success_message = '$success_message', max_submissions = '$max_submissions', stored_submissions = '$stored_submissions', use_captcha = '$use_captcha' WHERE section_id = '$section_id'");
-
-// Check if there is a db error, otherwise say successful
-if($database->is_error()) {
-	$admin->print_error($database->get_error(), ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
-} else {
-	$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
-}
-
-// Print admin footer
-$admin->print_footer();
-
+
+// Update settings
+$database->query("UPDATE ".TABLE_PREFIX."mod_form_settings SET header = '$header', field_loop = '$field_loop', footer = '$footer', email_to = '$email_to', email_from = '$email_from', email_subject = '$email_subject', success_message = '$success_message', max_submissions = '$max_submissions', stored_submissions = '$stored_submissions', use_captcha = '$use_captcha' WHERE section_id = '$section_id'");
+
+// Check if there is a db error, otherwise say successful
+if($database->is_error()) {
+	$admin->print_error($database->get_error(), ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
+} else {
+	$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
+}
+
+// Print admin footer
+$admin->print_footer();
+
 ?>
\ No newline at end of file
