Project

General

Profile

« Previous | Next » 

Revision 618

Added by thorn almost 17 years ago

Module form: user supplied input isn't lost on captcha-failure anymore

View differences:

trunk/CHANGELOG
18 18
+	added kewyword id to new file
19 19
#	Fixed some spelling errors in german language file
20 20
27-Jan-2008 Thomas Hornik
21
!	Module form: user supplied input isn't lost on captcha-failure anymore.
21 22
#	fixed 100%-cpu-load-event in CAPTCHA admin-tool.
22 23
+	Added Calc_ttf_image CAPTCHA.
23 24
!	Changed captcha/captcha.php to use table-layout for CAPTCHA.
trunk/wb/modules/form/save_field.php
51 51
	$type = $admin->get_post('type');
52 52
	$required = $admin->get_post('required');
53 53
}
54
$value = '';
54 55

  
55 56
// Update row
56 57
$database->query("UPDATE ".TABLE_PREFIX."mod_form_fields SET title = '$title', type = '$type', required = '$required' WHERE field_id = '$field_id'");
trunk/wb/modules/form/view.php
44 44

  
45 45
// Function for generating an optionsfor a select field
46 46
if (!function_exists('make_option')) {
47
function make_option(&$n) {
47
function make_option(&$n, $k, $values) {
48 48
	// start option group if it exists
49 49
	if (substr($n,0,2) == '[=') {
50 50
	 	$n = '<optgroup label="'.substr($n,2,strlen($n)).'">';
51 51
	} elseif ($n == ']') {
52 52
		$n = '</optgroup>';
53 53
	} else {
54
		$n = '<option value="'.$n.'">'.$n.'</option>';
54
		if(in_array($n, $values))
55
			$n = '<option selected="selected" value="'.$n.'">'.$n.'</option>';
56
		else
57
			$n = '<option value="'.$n.'">'.$n.'</option>';
55 58
	}
56 59
}
57 60
}
58 61
// Function for generating a checkbox
59 62
if (!function_exists('make_checkbox')) {
60 63
function make_checkbox(&$n, $idx, $params) {
61
	$field_id = $params[0];
62
	$seperator = $params[1];
64
	$field_id = $params[0][0];
65
	$seperator = $params[0][1];
63 66
	//$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;
64
	$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;
67
	if(in_array($n, $params[1]))
68
		$n = '<input class="field_checkbox" type="checkbox" id="'.$n.'" name="field'.$field_id.'['.$idx.']" value="'.$n.'" checked="checked">'.'<font class="checkbox_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = !document.getElementById(\''.$n.'\').checked;">'.$n.'</font>'.$seperator;
69
	else
70
		$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;
65 71
}
66 72
}
67 73
// Function for generating a radio button
......
70 76
	$field_id = $params[0];
71 77
	$group = $params[1];
72 78
	$seperator = $params[2];
73
	$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;
79
	if($n == $params[3])
80
		$n = '<input class="field_radio" type="radio" id="'.$n.'" name="field'.$field_id.'" value="'.$n.'" checked="checked">'.'<font class="radio_label" onclick="javascript: document.getElementById(\''.$n.'\').checked = true;">'.$n.'</font>'.$seperator;
81
	else
82
		$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;
74 83
}
75 84
}
76 85
// Generate temp submission id
......
161 170
		}
162 171
		if($field['type'] == 'textfield') {
163 172
			$vars[] = '{FIELD}';
164
			$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" maxlength="'.$field['extra'].'" value="'.$value.'" class="textfield" />';
173
			$values[] = '<input type="text" name="field'.$field_id.'" id="field'.$field_id.'" maxlength="'.$field['extra'].'" value="'.(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:$value).'" class="textfield" />';
165 174
		} elseif($field['type'] == 'textarea') {
166 175
			$vars[] = '{FIELD}';
167
			$values[] = '<textarea name="field'.$field_id.'" id="field'.$field_id.'" class="textarea">'.$value.'</textarea>';
176
			$values[] = '<textarea name="field'.$field_id.'" id="field'.$field_id.'" class="textarea">'.(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:$value).'</textarea>';
168 177
		} elseif($field['type'] == 'select') {
169 178
			$vars[] = '{FIELD}';
170 179
			$options = explode(',', $value);
171
			array_walk($options, 'make_option');
180
			array_walk($options, 'make_option', (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array()));
172 181
			$field['extra'] = explode(',',$field['extra']); 
173 182
			$values[] = '<select name="field'.$field_id.'[]" id="field'.$field_id.'" size="'.$field['extra'][0].'" '.$field['extra'][1].' class="select">'.implode($options).'</select>';
174 183
		} elseif($field['type'] == 'heading') {
......
179 188
		} elseif($field['type'] == 'checkbox') {
180 189
			$vars[] = '{FIELD}';
181 190
			$options = explode(',', $value);
182
			array_walk($options, 'make_checkbox',array($field_id,$field['extra']));
191
			array_walk($options, 'make_checkbox', array(array($field_id,$field['extra']),(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:array())));
183 192
			$options[count($options)-1]=substr($options[count($options)-1],0,strlen($options[count($options)-1])-strlen($field['extra']));
184 193
			$values[] = implode($options);
185 194
		} elseif($field['type'] == 'radio') {
186 195
			$vars[] = '{FIELD}';
187 196
			$options = explode(',', $value);
188
			array_walk($options, 'make_radio',array($field_id,$field['title'],$field['extra']));
197
			array_walk($options, 'make_radio', array($field_id,$field['title'],$field['extra'], (isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:'')));
189 198
			$options[count($options)-1]=substr($options[count($options)-1],0,strlen($options[count($options)-1])-strlen($field['extra']));
190 199
			$values[] = implode($options);
191 200
		} elseif($field['type'] == 'email') {
192 201
			$vars[] = '{FIELD}';
193
			$values[] = '<input type="text" name="field'.$field_id.'" onChange="return checkmail(this.form.field'.$field_id.')"  id="field'.$field_id.'" maxlength="'.$field['extra'].'" class="email" />';
202
			$values[] = '<input type="text" name="field'.$field_id.'" onChange="return checkmail(this.form.field'.$field_id.')"  id="field'.$field_id.'" value="'.(isset($_SESSION['field'.$field_id])?$_SESSION['field'.$field_id]:'').'" maxlength="'.$field['extra'].'" class="email" />';
194 203
			$java_mailcheck .= 'onChange="return checkmail(this.form'.$field_id.'" ';
195 204
		}
205
		if(isset($_SESSION['field'.$field_id])) unset($_SESSION['field'.$field_id]);
196 206
		if($field['type'] != '') {
197 207
			echo str_replace($vars, $values, $field_loop);
198 208
		}
......
351 361
		// Create blank "required" array
352 362
		$required = array();
353 363
		
364
		// Captcha
365
		if($use_captcha) {
366
			if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
367
				// Check for a mismatch
368
				if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
369
					$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
370
				}
371
			} else {
372
				$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
373
			}
374
		}
375
		if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
376

  
354 377
		// Loop through fields and add to message body
355 378
		// Get list of fields
356 379
		$query_fields = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_fields WHERE section_id = '$section_id' ORDER BY position ASC");
......
359 382
				// Add to message body
360 383
				if($field['type'] != '') {
361 384
					if(!empty($_POST['field'.$field['field_id']])) {
385
						if(isset($captcha_error)) $_SESSION['field'.$field['field_id']] = $_POST['field'.$field['field_id']];
362 386
						if($field['type'] == 'email' AND $admin->validate_email($_POST['field'.$field['field_id']]) == false) {
363 387
							$email_error = $MESSAGE['USERS']['INVALID_EMAIL'];
364 388
						}
......
379 403
				}
380 404
			}
381 405
		}
382
		
383
		// Captcha
384
		if($use_captcha) {
385
			if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
386
				// Check for a mismatch
387
				if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR $_POST['captcha'] != $_SESSION['captcha']) {
388
					$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
389
				}
390
			} else {
391
				$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
392
			}
393
		}
394
		if(isset($_SESSION['captcha'])) { unset($_SESSION['captcha']); }
395
		
406

  
396 407
		// Addslashes to email body - proposed by Icheb in topic=1170.0
397 408
		// $email_body = $wb->add_slashes($email_body);
398 409
		

Also available in: Unified diff