postcode en telefoonnummer check in mijn bestaande formulier
ik heb een bestaand formulier maar nu wil ik er een postcode check en telefoonnummer check invoeren.. maar wanneer ik deze script erinvoer doet die niks..
wat doe ik fout?
Quote:
Code (php)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
if(function_exists('date_default_timezone_set')) { date_default_timezone_set('Europe/Amsterdam'); }
define('LF', "\n");
// Get a value from the $_POST array (case insensitive!!)
function getPost($key, $trim = false, $lowercase = false, $int = false)
{
if(isset($_POST[$key]))
{
$v = stripslashes($_POST[$key]);
if($trim)
{
$v = trim($v);
}
if($int)
{
$v = intval($v);
}
elseif($lowercase)
{
$v = strtolower($v);
}
return $v;
}
return '';
}
// Default values
$field_1 = '';
$field_2 = '';
$field_3 = '';
$field_4 = '';
$sHtml = '';
$sFormError = '';
// Process form
if(empty($_POST['form']) == false)
{
$field_1 = getPost('field_1', true);
if(strlen($field_1) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
$field_2 = getPost('field_2', true);
if(strlen($field_2) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
$field_3 = getPost('field_3', true);
if(strlen($field_3) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
$field_4 = getPost('field_4', true);
if(strlen($field_4) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
}
if (isset($_REQUEST['field_2']))
// Als telefoonnummer is ingevuld, ga verder
// controleer telefoonnummer
if(preg_match("/^[0-9]{2}-[0-9]{8}$/",$_REQUEST['field_2']) OR preg_match("/^[0-9]{3}-[0-9]{7}$/",$_REQUEST['field_2']) OR preg_match("/^[0-9]{4}-[0-9]{6}$/",$_REQUEST['telnr']) OR preg_match("/^[0-9]{10}$/",$_REQUEST['field_2']))
{
// controleer postcode
if (preg_match("/[0-9]{4}[ ]?[a-z]{2}/i", trim($_REQUEST['field_3'])))
{
// Verstuur email
// Haal het streepje weg, in de email, tussen het telefoonnummer
$field_2 = str_replace('-', '', $_REQUEST['field_2']);
// Haal de spatie weg tussen de cijfers en letters postcode
$field_3 = str_replace(' ', '', $_REQUEST['field_3']);
// Show formz
if(empty($_POST['form']) || $sFormError)
{
$sHtml .= '<form action="" method="post">
<input name="form" type="hidden" value="form1">
<p><h1>Vul a.u.b. het onderstaande formulier in</h1></p>
' . $sFormError . '
<center><BR><table border="0" cellpadding="3" cellspacing="0"><tr>
<td align="left" valign="top">Naam *</td>
<td align="left" valign="top"><input name="field_1" type="text" value="' . htmlentities($field_1) . '"></td>
</tr>
<tr>
<td align="left" valign="top">Postcode *</td>
<td align="left" valign="top"><input name="field_2" type="text" value="' . htmlentities($field_2) . '"></td>
</tr>
<tr>
<td align="left" valign="top">Telefoonnummer *</td>
<td align="left" valign="top"><input name="field_3" type="text" value="' . htmlentities($field_3) . '"></td>
</tr>
<tr>
<td align="left" valign="top">Bericht *</td>
<td align="left" valign="top"><textarea name="field_4" cols="40" rows="6">' . htmlentities($field_4) . '</textarea></td>
</tr>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"><input type="submit" value="Verzenden"></td>
</table>
</center>
</form>';
}
else // Send form
{
$mail_to = '[email protected]';
$mail_from = '[email protected]';
$mail_subject = 'Contact formulier';
$mail_message = 'Formuliergegevens: ' . LF . LF
. 'Naam: ' . $field_1 . LF
. 'E-mail: ' . $field_2 . LF
. 'Telefoonnummer: ' . $field_3 . LF
. 'Bericht: ' . $field_4 . LF
. LF
. 'IP: ' . $_SERVER['REMOTE_ADDR'] . ', Datum: ' . date('d-m-Y') . ', Tijd: ' . date('H:i:s');
mail($mail_to, $mail_subject, $mail_message, 'From: ' . $mail_from);
$sHtml .= '<h1>Formulier verzonden</h1><p>Hartelijk dank voor het invullen van het formulier.</p>';
}
echo $sHtml;
?>
if(function_exists('date_default_timezone_set')) { date_default_timezone_set('Europe/Amsterdam'); }
define('LF', "\n");
// Get a value from the $_POST array (case insensitive!!)
function getPost($key, $trim = false, $lowercase = false, $int = false)
{
if(isset($_POST[$key]))
{
$v = stripslashes($_POST[$key]);
if($trim)
{
$v = trim($v);
}
if($int)
{
$v = intval($v);
}
elseif($lowercase)
{
$v = strtolower($v);
}
return $v;
}
return '';
}
// Default values
$field_1 = '';
$field_2 = '';
$field_3 = '';
$field_4 = '';
$sHtml = '';
$sFormError = '';
// Process form
if(empty($_POST['form']) == false)
{
$field_1 = getPost('field_1', true);
if(strlen($field_1) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
$field_2 = getPost('field_2', true);
if(strlen($field_2) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
$field_3 = getPost('field_3', true);
if(strlen($field_3) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
$field_4 = getPost('field_4', true);
if(strlen($field_4) == 0) { $sFormError = 'Vul a.u.b. alle verplichte velden in.'; }
}
if (isset($_REQUEST['field_2']))
// Als telefoonnummer is ingevuld, ga verder
// controleer telefoonnummer
if(preg_match("/^[0-9]{2}-[0-9]{8}$/",$_REQUEST['field_2']) OR preg_match("/^[0-9]{3}-[0-9]{7}$/",$_REQUEST['field_2']) OR preg_match("/^[0-9]{4}-[0-9]{6}$/",$_REQUEST['telnr']) OR preg_match("/^[0-9]{10}$/",$_REQUEST['field_2']))
{
// controleer postcode
if (preg_match("/[0-9]{4}[ ]?[a-z]{2}/i", trim($_REQUEST['field_3'])))
{
// Verstuur email
// Haal het streepje weg, in de email, tussen het telefoonnummer
$field_2 = str_replace('-', '', $_REQUEST['field_2']);
// Haal de spatie weg tussen de cijfers en letters postcode
$field_3 = str_replace(' ', '', $_REQUEST['field_3']);
// Show formz
if(empty($_POST['form']) || $sFormError)
{
$sHtml .= '<form action="" method="post">
<input name="form" type="hidden" value="form1">
<p><h1>Vul a.u.b. het onderstaande formulier in</h1></p>
' . $sFormError . '
<center><BR><table border="0" cellpadding="3" cellspacing="0"><tr>
<td align="left" valign="top">Naam *</td>
<td align="left" valign="top"><input name="field_1" type="text" value="' . htmlentities($field_1) . '"></td>
</tr>
<tr>
<td align="left" valign="top">Postcode *</td>
<td align="left" valign="top"><input name="field_2" type="text" value="' . htmlentities($field_2) . '"></td>
</tr>
<tr>
<td align="left" valign="top">Telefoonnummer *</td>
<td align="left" valign="top"><input name="field_3" type="text" value="' . htmlentities($field_3) . '"></td>
</tr>
<tr>
<td align="left" valign="top">Bericht *</td>
<td align="left" valign="top"><textarea name="field_4" cols="40" rows="6">' . htmlentities($field_4) . '</textarea></td>
</tr>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"><input type="submit" value="Verzenden"></td>
</table>
</center>
</form>';
}
else // Send form
{
$mail_to = '[email protected]';
$mail_from = '[email protected]';
$mail_subject = 'Contact formulier';
$mail_message = 'Formuliergegevens: ' . LF . LF
. 'Naam: ' . $field_1 . LF
. 'E-mail: ' . $field_2 . LF
. 'Telefoonnummer: ' . $field_3 . LF
. 'Bericht: ' . $field_4 . LF
. LF
. 'IP: ' . $_SERVER['REMOTE_ADDR'] . ', Datum: ' . date('d-m-Y') . ', Tijd: ' . date('H:i:s');
mail($mail_to, $mail_subject, $mail_message, 'From: ' . $mail_from);
$sHtml .= '<h1>Formulier verzonden</h1><p>Hartelijk dank voor het invullen van het formulier.</p>';
}
echo $sHtml;
?>
Er zijn nog geen reacties op dit bericht.