-
Notifications
You must be signed in to change notification settings - Fork 0
/
id_form_check.php3
62 lines (53 loc) · 1.38 KB
/
id_form_check.php3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?
$errors= array( );
if ( empty( $error_marker ) )
$error_marker = " * ";
function check_data( $required, $custom, $submit_flag, $success_page ) {
global $errors;
if ( empty( $GLOBALS[$submit_flag] ) )
return 1;
reset( $required );
while ( list( $key, $val ) = each( $required ) ) {
if ( empty( $GLOBALS[$key] ))
$errors[$key] = $val;
}
while ( list( $key, $val ) = each( $custom ) ) {
$ret = $val( $key );
if ( is_string( $ret ) )
$errors[$key] = $ret;
}
if ( ! count( $errors ) ) {
$errors = array();
return 0;
}
return 1;
}
function mark_error( $field, $txt ) {
global $errors;
global $error_marker;
if ( ! empty( $errors[$field] ))
print ereg_replace("%text%", $txt, $error_marker );
else
print $txt;
}
function report_errors( $template ) {
global $errors;
$str="";
if ( ! count( $errors ) )
return 0;
reset( $errors );
while ( list( $key, $val ) = each ( $errors ) ) {
$str .= "$val<br>";
}
$template = ereg_replace("%error_report%", $str, $template );
print "$template";
}
// custom check function: accepts fieldname -- returns string on error and 1 on success
function validate_mail( $field ) {
// quick and dirty mail check nicked from phil gyford
if ( ! eregi( "[-0-9=?.A-Z&\'*+\\/^_`a-z{|}!#$%~]+@[-0-9=?A-Z&\'*+\\/^_`a-z{|}!#$%~]+\.[-0-9=?A-Z&\'*+\\/^_`a-z{|}!#.$%~]+", $GLOBALS[$field] ) ) {
return "<LI>email address";
}
return 1;
}
?>